Convert Array Of Comma Separated Strings To Array Of Objects
I want to convert an array to object with key-value pairs. The array is like this: latLngArray = [ '52.12,-106.65', '53.53,-113.50' ] I want to convert it to array of objects lik
Solution 1:
Try this with simple map()
latLngArray = ['52.12,-106.65', '53.53,-113.50'];
result = latLngArray.map(coords => {
const [lat, lng] = coords.split(',');
return {
lat,
lng
};
});
console.log(result)
Post a Comment for "Convert Array Of Comma Separated Strings To Array Of Objects"