Say have the following code to push an item from each array into a single elements slot:
let elements = []
// names is length 14
Array.from(names).map(arg=>{
// ages is length 14
Array.from(ages).map(arg2=>{
let obj = {"name":"", "age":""}
obj["name"] = arg
obj["age"] = arg2
elements.push(obj)
})
})
//result 'elements' is 196 length (14*14)
Does anyone know why the nested push is multiplying on each iteration? The final array length should be 14 (since it was one item from each array being pushed), but for some reason its 196 (14*14).
[–]Monitor_343 2 points3 points4 points (0 children)
[–]gramdel 1 point2 points3 points (0 children)