Getting An Item Position from Array if it matches the value

image

This the output of my GS API Call. I want to get the index position of 8 Jan which in this case is 2.

You can use the built-in function get

e.g.:

{{ get(1.body.values.1; 2) }}

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

samliew – request private consultation

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

1 Like

It will not be always 8 Jan it is just an example. For the next step i want to get the index of value i pass. something like indexOf(array,“8 Jan”).

There is no indexOf function for arrays in Make.

The workaround is to Iterate the array, and then create a filter, then you can use the “Bundle order position” variable.

Input

Screenshot_2024-06-21_130617

Filter

Output

As you can see, the position of “Jan 15” in the array is 3.

samliew – request private consultation

Join the Make Fans 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.

View Module Export Code

JSON

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 158,
                    "module": "json:ParseJSON",
                    "version": 1,
                    "parameters": {
                        "type": ""
                    },
                    "mapper": {
                        "json": "{\n  \"array\": [\n    \"Jan 1\",\n    \"Jan 8\",\n    \"Jan 15\",\n    \"Jan 22\",\n    \"Jan 29\"\n  ]\n}"
                    },
                    "metadata": {
                        "designer": {
                            "x": -2316,
                            "y": -1399
                        },
                        "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": 160,
                    "module": "builtin:BasicFeeder",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "array": "{{158.array}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": -2073,
                            "y": -1397
                        },
                        "restore": {
                            "expect": {
                                "array": {
                                    "mode": "edit"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "array",
                                "type": "array",
                                "label": "Array",
                                "mode": "edit",
                                "spec": []
                            }
                        ]
                    }
                },
                {
                    "id": 163,
                    "module": "util:TextAggregator",
                    "version": 1,
                    "parameters": {
                        "rowSeparator": "",
                        "feeder": 160
                    },
                    "filter": {
                        "name": "filter",
                        "conditions": [
                            [
                                {
                                    "a": "{{160.value}}",
                                    "o": "text:equal",
                                    "b": "Jan 15"
                                }
                            ]
                        ]
                    },
                    "mapper": {
                        "value": "{{160.`__IMTINDEX__`}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": -1785,
                            "y": -1396,
                            "messages": [
                                {
                                    "category": "last",
                                    "severity": "warning",
                                    "message": "A transformer should not be the last module in the route."
                                }
                            ]
                        },
                        "restore": {
                            "parameters": {
                                "rowSeparator": {
                                    "label": "Empty"
                                }
                            },
                            "extra": {
                                "feeder": {
                                    "label": "Iterator [160]"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "rowSeparator",
                                "type": "select",
                                "label": "Row separator",
                                "validate": {
                                    "enum": [
                                        "\n",
                                        "\t",
                                        "other"
                                    ]
                                }
                            }
                        ],
                        "expect": [
                            {
                                "name": "value",
                                "type": "text",
                                "label": "Text"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}

samliew – request private consultation

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

2 Likes

Thanks @samliew , I think this will work but how do I convert my body array to json. this is how my array is:

image

I tried this but i dont think it is a right way.

The first module is just to output an example array.

You can delete it and replace with the module that you showed in your first post.

samliew – request private consultation

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

2 Likes

Thank you so much for the solution and patience @samliew !!

1 Like