[Vuejs]-Map object with array in javascript

0👍

Map through array of objects you get from API, it returns new array with objects with desired fields.

axios.get("api/gallery").then(response => {
  this.dataImages = response.data.data.map((obj, index) => {
    return {
      id: obj.id,
      src: obj.path,
      alt: `Alt image ${index}`
    };
  });
});

Leave a comment