2๐
โ
Use JavaScript map function. Your code would become:
let route = res.data.data;
const ddd = route.map((element) => {
return {
lat: element.latitude,
lng: element.latitude,
};
});
1๐
Use Array.map
:
let route = res.data.data;
console.log('data to be loop: ', route)
let ddd = route.map(x => {
return {
lng: x.longitude,
lat: x.latitude
}
})
console.log('final data: ', ddd)
Source:stackexchange.com