How to add an array of object to a record?

Answered

Hey there, I am asking probably a basic question but how do you add an object within a record?

I have a column called "options" that could be dynamically filled with some "options" and a column "user_id "that will automatically have the user_id as value.

I receive data from input, called "options" it is a string array that I would like to transform as an object to define each value as a key and set the user_id as a value for those keys and then add them in my record.
for example, if my input "options" is ["pizza","hot-dog","Hamburger"]

I want to transform it as:

[ { options: 'pizza', "user_id": 384 }, { options: 'hot-dog', "user_id": 384 }, { options: 'Hamburger', "user_id": 384 } ];

and be able to add it directly to my record.

Here is what I have been able to do so far, but the issue is, it only adds one record for the last value of the each loop created, if I move the "add record" inside the "each loop" then it adds me 3 rows.

In my case, I just want to add more line in my object (see screenshot above).

how to do it?


3 replies