computed: {
poolList () {
const poolList = []
this.bettingObjectList.forEach(bettingObject => {
poolList.push(...bettingObject.poolList)
})
return poolList
},
}
think it"s tedious, can it be simplified
computed: {
poolList () {
const poolList = []
this.bettingObjectList.forEach(bettingObject => {
poolList.push(...bettingObject.poolList)
})
return poolList
},
}
think it"s tedious, can it be simplified
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);
Previous: Where is the asynchronism of Sanic?
A solution that conforms to the meaning of the question function unique(arr) { const res = new Map(); return arr.filter((a) => !res.has(a) && res.set(a, 1)) } because map key is unique, you can change the an in res.has (a) to whate...
for example, duplicates according to the name attribute in the an array element. is this the simplest way? function unique(arr) { const res = new Map(); return arr.filter((a) => !res.has(a.name) && res.set(a.name, 1)) } reference...
is there a method like push, but instead of inserting an element into an array, add another array similar to java s addAll method all I know so far is concat, but he returns the new array instead of making changes on the original array, ...
this is what I do now. Is there a better way? let flag = true const listA = [1, 2, 3] const listB = [2, 3, 4] if (listA.length !== listB.length) { flag = false } else { listA.forEach(item => { if (listB.indexOf(it...
uses the login permission judgment in vue-element-admin, which is basically introduced and loaded according to it, but it still prompts you to report an error main.js . import Vue from vue import App from . App import router from . router i...
as follows, I have two functions written in promis form function one verifyGA(type){ let that = this; return new Promise((resolve,reject) => { that.$post( user verifyGA ,{ gaCode:that.gaCode, captchaType:...
there is a class A , SubA inherits A, but the console reports an error Class constructor xxx cannot be invoked without new how to solve it? A class A{ constructor() {} }; export default A A import A from xxx class SubA extends A{ co...