I have an array that look like these: these are coordinates from an API
const paths = [
[22.372081, 114.107877],
[22.326442, 114.167811],
[22.284419, 114.159510]
];
I need to convert it to something like these: with keys of lat and lng for each row.
{lat: 22.372081, lng: 114.107877},
{lat: 22.326442, lng: 114.167811},
{lat: 22.284419, lng: 114.159510}
I only have this short code but its not working what i wanted.
const waypts= [];
const paths = [
[22.372081, 114.107877],
[22.326442, 114.167811],
[22.284419, 114.159510]
];
for(let i = 0; i < paths.length; i++) {
waypts.push({
location: new google.maps.LatLng(paths[i]),
stopover: false,
});
console.log(paths[i]);
}
console.log(waypts);
paths.map(([lat,lng])=>({lat,lng}))?