[Vuejs]-Mapping data with 2 dimensional array with AXIOS and VueJs

3👍

Just return an array from the map functions’ callback with item.origine and item.nb

let data = [{
  "origine": "",
  "nb": 15
}, {
  "origine": "?",
  "nb": 18
}, {
  "origine": "?L",
  "nb": 1
}, {
  "origine": "G",
  "nb": 298
}, {
  "origine": "I",
  "nb": 51
}, {
  "origine": "L",
  "nb": 1735
}, {
  "origine": "L?",
  "nb": 1
}, {
  "origine": "O",
  "nb": 4
}]

let mappedData = data.map(item => {
  return [item.origine, item.nb];
})

console.log(mappedData)

2👍

Well, you literally have all the answers, you just need to combine them:

axios
  .get('../api/civitasorigine/' + this.searchInputcivitas)
  .then(response => {
    this.origines = response.data.map(obj => {
      const rObj = {};
      rObj[obj.origine] = obj.nb;
      return rObj;
    })
  })

Leave a comment