-4

I had two arrays that I wanted to combine in an array of arrays for coordinate storing.

const x = [1,2,3];
const y = [2,4,6];
const coords = x.map((el, index) => [el, y[index]]);
print(coords); // spits out the correct [[1,2],[2,4],[3,6]]

Now I want to do the reverse: split an array inside an array to separate arrays:

const new_coords = [[0,0],[1,4],[2,9]];
//do something
const x_new = [0,1,2];
const y_new = [0,4,9];

What would be the easiest/fastest way to accomplish this?

2

1 Answer 1

1
const x_new = new_coords.map(a=>a[0]);
const y_new = new_coords.map(a=>a[1]);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.