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
]
]
CodePudding user response:
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);
CodePudding user response:
const a = [
{ latitude: '113.232160114', longitude: '-1.786978559' },
{ latitude: '113.211955085', longitude: '-1.790031776' }
];
console.log(a.map(({latitude:i, longitude:j})=>[i,j]));