Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to remove key keep the value in array of object javascript

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading