-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?

beedeeguan
  • 41
  • 5
  • 1
    Show us what you have tried. SO isn't a free code writing service. The objective here is for you to post your attempts to solve your own issue and others help when they don't work as expected. See [ask] and [mcve] – charlietfl Mar 23 '21 at 22:15
  • Does this answer your question? [How to get all index of an array to new array](https://stackoverflow.com/questions/66695277/how-to-get-all-index-of-an-array-to-new-array) – Sebastian Simon Mar 23 '21 at 22:27

1 Answers1

1
const x_new = new_coords.map(a=>a[0]);
const y_new = new_coords.map(a=>a[1]);
Joe Iddon
  • 20,101
  • 7
  • 33
  • 54