I have 2 arrays
const x = [0, 1, 2, 3, 4, 5]
const y = [6, 7, 8, 9, 10, 11]
I'm trying to combine the two array into an array of objects such that it becomes:
[{x: 0, y: 6}, {x: 1, y: 7}, {x: 2, y: 8}, {x: 3, y: 9}, {x: 4, y: 10}, {x: 5, y: 11}]
Currently what I did was to loop the length of one of the arrays then push the object to the new array.
let newArray = []
for(i = 0; i < x.length; i++) {
newArray.push({x: x[i], y: y[i]})
}
Just wondering if there is a more efficient way to do this, thanks!