[Vuejs]-Reformat JSON object

1👍

This is easy to do with a map, which applies the same function to every element of an array

let obj = { sliderArray: [
    "../assets/slides/1.jpg",
    "../assets/slides/2.jpg",
  ]
};

function formatArray(a) {
  return a.map(x => { return { url: require(x) } });
}

obj.sliderArray = formatArray(obj.sliderArray);

Leave a comment