JavaScript 多个数组合并中的对象

JavaScript object inside Multiple array merge

我在数组值的对象列表中有一个对象,我想合并对象值 感谢帮助

const List = {
    school1: [{studentname:'1'},{studentname:'2'}]
    school2: [{studentname:'21'},{studentname:'22'}] 
    school3: [{studentname:'31'},{studentname:'32'}]
}

Trying Get like this 
const List = [{studentname:'1'},{studentname:'2'},{studentname:'21'},{studentname:'22'},{studentname:'31'},{studentname:'32'}]





您可以使用 Object.values() and Array.flat() 得到想要的结果:

const List = {
    school1: [{studentname:'1'},{studentname:'2'}],
    school2: [{studentname:'21'},{studentname:'22'}], 
    school3: [{studentname:'31'},{studentname:'32'}]
}

const result = Object.values(List).flat();
console.log('Result:', result)

    
.as-console-wrapper { max-height: 100% !important; }

var a = {
    a1: [{name:'s1'}, {name: 's2'}],
    a2: [{name:'s3'}, {name: 's4'}],
    a3: [{name:'s5'}, {name: 's6'}],
}
var list = [];
Object.keys(a).forEach(x => {list = [...list, ...a[x]]})
console.log(list)

暴力破解:

const List = {
    school1: [{studentname:'1'},{studentname:'2'}],
    school2: [{studentname:'21'},{studentname:'22'}],
    school3: [{studentname:'31'},{studentname:'32'}]
}

let List2 = [];
for(let i of Object.values(List)){
    List2.push(i)
}
console.log(List2)