Can the code for making new arrays in the computed of this vue be simplified?

computed: {

poolList () {
  const poolList = []
  this.bettingObjectList.forEach(bettingObject => {
    poolList.push(...bettingObject.poolList)
  })
  return poolList
},

}

think it"s tedious, can it be simplified

Aug.16,2021

of course it can be simplified. The logic is very simple. Extract the subarray and flatten it. Traditionally, you can write

like this.
computed: {
  poolList() {
    return [].concat(...this.bettingObjectList.map(({poolList}) => poolList));
  },
},

of course, you can also be more aggressive and directly use Array.prototype.flatMap ()

.
return this.bettingObjectList.flatMap(({poolList}) => poolList);
Menu