Add array to table as a new column

Hello everyone!

Please help me to write a custom code.
The code will take a table and an array as inputs. The code should add the array as a new column to the table, with each value of the array appearing in the row corresponding to its index. Finally, the code should output the updated table with the new array column. (We know that the length of the array matches the number of rows in the table)

Please let me know if it's not clear enough. Looking forward to hear your thoughts!

Hey @MJ23! You would need to append the array to the query that populates your table initially. Assuming this is a SQL query, you can add a transformer to the query along the lines of:

let yourArray = {insert appropriate reference to your array here};
let queryArray = formatDataAsArray(data);

let combinedArray = queryArray.map((row, index) => {
  return {
    ...row,
    newColumn: yourArray[index]
  };
});

return combinedArray

Let me know how you get on trying something like this :grinning:

1 Like