Reputation: 89
I have this object:
[
{
"latitude": "113.232160114",
"longitude": "-1.786978559"
},
{
"latitude": "113.211955085",
"longitude": "-1.790031776"
}
]
is there any possible way to make it look like this using JavaScript?
[
[
113.232160114,
-1.786978559
],
[
113.211955085,
-1.790031776
]
]
Upvotes: 1
Views: 802
Reputation: 198324
Yes, with one single line, and two built-in functions: Array.prototype.map
produces an array obtained by applying a function to each element of an array, and Object.values
produces a list of enumerable properties of an object.
const data = [
{
"latitude": "113.232160114",
"longitude": "-1.786978559"
},
{
"latitude": "113.211955085",
"longitude": "-1.790031776"
}
];
const result = data.map(Object.values);
console.log(result);
Upvotes: 4
Reputation: 8087
const a = [
{ latitude: '113.232160114', longitude: '-1.786978559' },
{ latitude: '113.211955085', longitude: '-1.790031776' }
];
console.log(a.map(({latitude:i, longitude:j})=>[i,j]));
Upvotes: 1