Function to join arrays, in index order

Which function will join arrays for me in the following way:
The function will take an element from each array according to their index, and create a collection with 2 objects, the first is a STEP key whose value is the corresponding element in order, from array 1
And the second object is with an answer key with a value of the corresponding element in order, from array 2
Given an example:
I have array 1 [idMen,IdWomen] array 2 [123,321]
I want to create one array from them in this way:
[{“step”:“idMen”,“answer”:“123”},{“step”:“IdWomen”,“answer”:“321”}]

Welcome to the Make community!

Yes, that is possible. You’ll need a minimum of three modules:
Screenshot_2025-04-27_200435

This is just an example. Your final solution may or may not look like this depending on your requirements and actual data.

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

Module Export - quick import into your scenario

You can copy and paste this module export into your scenario. This will import the modules (with fields/settings/filters) shown in my screenshots above.

  1. Move your mouse over the line of code below. Copy the JSON by clicking the copy button on the right of the code, which looks like this:

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

  3. Click on each imported module and re-save it for validation. There may be some errors prompting you to remap some variables and connections.

JSON module export — paste this directly in your scenario

{"subflows":[{"flow":[{"id":339,"module":"util:SetVariables","version":1,"parameters":{},"mapper":{"variables":[{"name":"array1","value":"{{split(\"idMen,IdWomen\"; \",\")}}"},{"name":"array2","value":"{{split(\"123,321\"; \",\")}}"}],"scope":"roundtrip"},"metadata":{"designer":{"x":1102,"y":-2549,"name":"Input Arrays"}}},{"id":340,"module":"builtin:BasicFeeder","version":1,"parameters":{},"mapper":{"array":"{{339.array1}}"},"metadata":{"designer":{"x":1345,"y":-2547}}},{"id":343,"module":"util:TextAggregator","version":1,"parameters":{"rowSeparator":"other","otherRowSeparator":",","feeder":340},"mapper":{"value":"{\n\"step\":\"{{340.value}}\",\n\"answer\":\"{{339.array2[340.`__IMTINDEX__`]}}\"\n}"},"metadata":{"designer":{"x":1587,"y":-2548},"parameters":[{"name":"rowSeparator","type":"select","label":"Row separator","validate":{"enum":["\n","\t","other"]}},{"name":"otherRowSeparator","type":"text","label":"Separator"}]},"flags":{"stopIfEmpty":true}},{"id":344,"module":"json:ParseJSON","version":1,"parameters":{"type":""},"mapper":{"json":"{\n  \"array\": [{{343.text}}]\n}"},"metadata":{"designer":{"x":1831,"y":-2548,"messages":[{"category":"last","severity":"warning","message":"A transformer should not be the last module in the route."}]},"parameters":[{"name":"type","type":"udt","label":"Data structure"}]}}]}],"metadata":{"version":1}}

Note: Did you know you can reduce the size of blueprints and module export code like the above, using the Make Blueprint Scrubber?

@samliew

Alternatively, you can just do it with one special module.

Output

For more information on how to get this module, see [Free App] My Toolbox of Useful Modules

Module Export - quick import into your scenario

You can copy and paste this module export into your scenario. This will import the modules (with fields/settings/filters) shown in my screenshots above.

  1. Move your mouse over the line of code below. Copy the JSON by clicking the copy button on the right of the code, which looks like this:

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

  3. Click on each imported module and re-save it for validation. There may be some errors prompting you to remap some variables and connections.

JSON module export — paste this directly in your scenario

{"subflows":[{"flow":[{"id":345,"module":"util:SetVariables","version":1,"parameters":{},"mapper":{"variables":[{"name":"array1","value":"{{split(\"idMen,IdWomen\"; \",\")}}"},{"name":"array2","value":"{{split(\"123,321\"; \",\")}}"}],"scope":"roundtrip"},"metadata":{"designer":{"x":1092,"y":-3048,"name":"Input Arrays"}}},{"id":346,"module":"app#sams-toolbox-mls54z:basicjs","version":1,"parameters":{},"mapper":{"code":"const output = input.array1.map((v, i) => {\n  return {\n    \"step\": v,\n    \"answer\": input.array2[i]\n  }\n});\n\n({ array: output })","input":[{"key":"array1","value":"{{345.array1}}"},{"key":"array2","value":"{{345.array2}}"}]},"metadata":{"designer":{"x":1340,"y":-3050}}}]}],"metadata":{"version":1}}

Note: Did you know you can reduce the size of blueprints and module export code like the above, using the Make Blueprint Scrubber?

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

@samliew

2 Likes