Get length of arrays which are not empty

Hello everyone,

I have a repeater module that I would like to repeat depending on the number of values in the array that are not empty (the array length is 10, however the number of values that are not empty can vary from 1-10)

I have tried this formula in a repeater module : {{length(1.Entry-Name != β€œβ€)}} however it is outputting length of 4, when based on the input, it should be outputting 2.

Any suggestions on the correct formula for this would be a great help thank you.


The better answer is do not use a repeater module at all.

When there is an ARRAY, think ITERATOR.

Then, you can remove empty strings from an array with the built-in function remove

e.g.:

{{ remove(1.array; emptystring) }}

Screenshot_2024-07-29_100705

Output:

Screenshot_2024-07-29_100721

For more information, see the function documentation in the Help Center.

Here are some useful links and guides you can use to learn more on how to use the Make platform, apps, and app modules. I found these useful when I was learning Make, and hope they might benefit you too β€”

General

Help Center Basics

Articles & Videos

Hope this helps!

samliew – request private consultation

Join the unofficial Make Discord server to chat with other makers!

1 Like

Module Export

You can copy and paste this module export into your scenario. This will paste the modules shown in my screenshots above.

  1. Copy the JSON code below by clicking the copy button when you mouseover the top-right of the code block
    Screenshot_2024-01-17_200117

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the canvas.

  3. Click on each imported module and save it for validation. You may be prompted to remap some variables and connections.

Click to Expand Module Export Code

JSON - Copy and Paste this directly in the scenario editor

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 89,
                    "module": "builtin:BasicFeeder",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "array": "{{remove(1.array; emptystring)}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 234,
                            "y": -2769
                        },
                        "restore": {
                            "expect": {
                                "array": {
                                    "mode": "edit"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "array",
                                "type": "array",
                                "label": "Array",
                                "mode": "edit",
                                "spec": []
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}

samliew – request private consultation

Join the Make Fans Discord server to chat with other makers!

Hi @hb ,

Welcome to Make Community!

Please check the below images and notes.
Input Array:-

Length Function:-

Output :-
image

{{length(remove(1.array; emptystring))}}

Please use this function in the repeater to get the length of a non-empty array.

If you require additional assistance, please don’t hesitate to reach out to us.
MSquare Support
| Book Live Implementation
Visit us here
Youtube Channel

Thank you for your reply. For some reason, the formula is not working when i’ve tested it. its showing length of 3 even though the 3 its items that are empty. any suggestions what could be going wrong?

if not please would you be able to send your example code please?



Screenshot_2024-07-31_100752

Module Export

You can copy and paste this module export into your scenario. This will paste the modules shown in my screenshots above.

  1. Copy the JSON code below by clicking the copy button when you mouseover the top-right of the code block

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the canvas.

  3. Click on each imported module and save it for validation. You may be prompted to remap some variables and connections.

Click to Expand Module Export Code

JSON - Copy and Paste this directly in the scenario editor

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 128,
                    "module": "json:ParseJSON",
                    "version": 1,
                    "parameters": {
                        "type": ""
                    },
                    "mapper": {
                        "json": "{\n  \"array\": [\n\"Horse Riding\",\n\"Horse Riding\",\n\"\",\n\"\",\n\"\",\n\"\",\n\"\",\n\"\",\n\"\",\n\"\"\n  ]\n}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 2499,
                            "y": -761,
                            "name": "Example array"
                        },
                        "restore": {
                            "parameters": {
                                "type": {
                                    "label": "Choose a data structure"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "type",
                                "type": "udt",
                                "label": "Data structure"
                            }
                        ],
                        "expect": [
                            {
                                "name": "json",
                                "type": "text",
                                "label": "JSON string",
                                "required": true
                            }
                        ]
                    }
                },
                {
                    "id": 127,
                    "module": "builtin:BasicFeeder",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "array": "{{remove(128.array; emptystring)}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 2796,
                            "y": -757,
                            "name": "Repeat non-empty items",
                            "messages": [
                                {
                                    "category": "last",
                                    "severity": "warning",
                                    "message": "A transformer should not be the last module in the route."
                                }
                            ]
                        },
                        "restore": {
                            "expect": {
                                "array": {
                                    "mode": "edit"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "array",
                                "type": "array",
                                "label": "Array",
                                "mode": "edit",
                                "spec": []
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}

Hope this helps! Let me know if there are any further questions or issues.

samliew – request private consultation

Join the Make Fans Discord server to chat with other makers!