Trying to solve this question and having another question by myself instead.
let arr = [
{"Footprint_Shape":["L-Shape","H-Shape","T-Shape"]},
{"Num_of_Floors":[1,2]}
]
let answer = [];
arr[0]["Footprint_Shape"].forEach(x => {
console.log('x: ',x) //Keeping loop on first array, print the element
let newObj = {};
newObj["Footprint_Shape"] = x;
arr[1]["Num_of_Floors"].forEach(y => {
console.log('y: ',y)
newObj["Num_of_Floors"] = y
answer.push(newObj);
})
});
console.log(answer);
Below is the chrome logging which is what I was expecting.
But when I logging the answer, below is the result instead:
For each of the iteration in arr[1]["Num_of_Floors"]
, clearly I printed the y
value correctly and immediately construct the object and push into array but seems like value 1
has always been overwritten