I want to get an array of the values of each object I have.
I have this:
const numDataPoints = [
{
x0: {x: 807, y: 625},
x1: {x: 15, y: 20},
x2: {x: 5, y: 20}
},
{
x0: {x: 11, y: 6},
x1: {x: 16, y: 21},
x2: {x: 7, y: 22}
}
];
I want this:
[
[807, 625],
[15, 20],
[5, 20],
[11, 6],
[16, 21],
[7, 22]
]
I tried this:
numDataPoints.map((array) => array.map(axis => [axis.x, axis.y]));
but it throws this error:
Uncaught
TypeError:array.mapis not a function
array.maphere[[[807, 625], [15, 20], [5, 20]], [[11, 6], [16, 21], [7, 22]]]what you’d need here?numDataPoints.mapis fine.mapthe outside array just fine, it's the inside object(s) where you'd likely need to loop through object keys rather than using array methods. Looping through object keys should be reasonably well documented here on SO as it's a commonly asked question.