The first array is something like this
arrayA = [{x:"abc",y:2},{x:"cde",y:3},{x:"xyz",y:2}]
The second array is
arrayB = ["abc","cde","efg","ghi","xyz"]
I want to insert the element of arrayB as key-value pair which is missing in arrayA as key is the element from arrayB and value will be 0 I want the resultant arrayResult something like this
arrayResult = [{x:"abc",y:2},{x:"cde",y:3},{x:"efg",y:0},{x:"ghi",y:0},{x:"xyz",y:2}]
I tried this but didn't get the required result
for (let i = 0; i < arrayB.length; i++) {
for (let j = 0; j <arrayA.length; j++) {
if(arrayB[i] !== arrayA[j].x) {
arrayA.push({x:arrayB[i],y:0})
}
}
}
I am new to js. can anyone help me with this?