Creating and Array and iterating over it

Hello,

I am learning how to use more complicated functions of Make now.
I have the following thing I want to do:

I have to collums from which I want to create an array.
Collum 1: Age
Collum 2: Price

Each age has it’s own Price, let’s say:
10: 150
11:170
12:180

Those values are static and will not change, so what I want to do is to input this array manually into my Make scenario, so the next Module can iterate over it.
It receives the age from a different module I already configured and it need to pull out the corresponding price.

How would one achieve such a functionality? I have been trying different modules but I still have hard time understanding the correct path.

Thank you!

Welcome to the Make community!

Yes, that is possible. You’ll need a minimum of one module:

Screenshot_2024-08-13_100827 (2)

Output

Screenshot_2024-08-13_100816

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

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

@samliew

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":69,"module":"json:ParseJSON","version":1,"mapper":{"json":"{\"myArray\": [\n{\n  \"age\": 10,\n  \"price\": 150\n},\n{\n  \"age\": 11,\n  \"price\": 170\n},\n{\n  \"age\": 12,\n  \"price\": 180\n}\n]}"},"metadata":{"designer":{"x":-207,"y":-327}}}]}],"metadata":{"version":1}}

Thank you for the reply!

And what would be the best way to get the correct price for the age? I have a different module that gives the age of the person and I need to have a final module that takes the age and the array and is able to give me the correct price output.

What would you suggest to be the best approach? Ideally in a way that won’t burn my operations if there is a lot of data to iterate through

You can use the map-first combo functions with this to do it without using a single operation.

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

@samliew


P.S.: Did you know, the concepts of about 70% of questions asked on this forum are already covered in the Make Academy. Investing some effort into it will save you lots of time and frustration using Make later!

What is the map-first combo function? Could you explain and example of how to implement it? :smiley:

{{ first(map(array; "property"; "key"; "value")) }}

e.g.:

{{ first(map(1.array; "price"; "age"; "10")) }}

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

@samliew


P.S.: Did you know, the concepts of about 70% of questions asked on this forum are already covered in the Make Academy. Investing some effort into it will save you lots of time and frustration using Make later!

1 Like