[Vuejs]-Vuejs get data from array and place them in another array

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)

Leave a comment