Add value to output of script output

I currently have javascript which iteratively runs an api query for each value (item.data_ipm_monitor_uuid) in an array I specified.

This works perfectly.

const arr = sql_prod_se.data //your array of things to iterate over
const query = API_RS_PagespeedJS // your query to trigger for each

const promises = arr.map((item) => {
  
  return query.trigger({
      additionalScope: {
        ph: item.data_ipm_monitor_uuid
      }
  
   });


});


return Promise.all(promises)

This produces this output...
image

However, I would like to insert the value (item.data_ipm_monitor_uuid) into the results array (perhaps just above or below the message: "Reading results was successful" - or even in place of) so I know which uuid the API results belong to.

Can you please help?

Can be more specific? What should the array itself look like when constructed the way you would like it to be?

Thank you

I just need the new line inserting anywhere for each record

something like this would be great (ie. at the start of each record)

image

Where are you getting that information for the site_uuid? Another query, a list, etc.?

the site_uuid will be available in the transformer. I just dont know how to add it in the array

Loop through the array and concatenate it to each value in the array - hard to tell as I don't see an example of your array specifically

the array is returned as a response from an API

I can access the resulting array in a transformer, however, I do not know how to loop through arrays and update the values (or insert a new value)

If easier, Im even happy to reaplace "message" (ie. instead of "Reading all results was successful") with the site_uuid

I guess what I am asking is what does the site_uuid look like in the transformer. Is it only one site_uuid or multiple? Will it be the same amount of site_uuids as the the number of keys in your array you want to add to?

Good question sorry for my lack of detail

There will be different site_uuid but only one per record

I can write the logic to determine the site_uuid relevant to each record

If I can have help on how to insert the same single value into each record, in the array, I can write the code to use site_uuid

Based on how you have the data constructed you could try something like this:

const myArray = ["message:Reading results was successful", "error_code:null"];
const site_uuidArray = ["site_uuid:1234"];

for (let i = 0; i < site_uuidArray.length; i++) {
  const currentItem = site_uuidArray[i];
  if (!myArray.includes(currentItem)) {
    myArray.push(currentItem);
  }
}

console.log(myArray);
return myArray