Hello all.
I have two arrays that contain a dynamic number of objects (per input).
I am trying to do the following:
For each object in the first array, check if a certain value exists in any of the objects in the second array, and if so extract another value from that object.
I've tried doing so with the following function:
var array1 = msg.payload[0];
var array2 = msg.payload[1];
for(let i = 0; i < array2.length; i++){
if (array2[i]["order_number"] === array1[i]["order_number"]){
array2.push({"city" : array1[i]["city"]})
}
}
msg.payload = array2;
return msg;
This works fine only if one of the arrays contain a single object. Any more than that and I receive an "order_number" undefined.
I've tried looping through the entire second array within the first loop with the following:
var array2 = msg.payload[0];
var array1 = msg.payload[1];
for(let i = 0; i < array1.length; i++){
for(let i = 0; i < array2.length; i++){
if (array1[i]["order_number"] === array2[i]["order_number"]){
array1.push({"city" : array2[i]["city"]})
}
}}
msg.payload = array1;
return msg;
This however causes my node-red to crash each time I inject a payload.
What am I doing wrong?
Thanks for any help.