举例子:这是一个一维数组对象
formList:[{ affiliation: 0 affiliationInfo: "签署方1" defaultValue:xxx },{ affiliation: 0 affiliationInfo: "签署方1" defaultValue:xxx },{ affiliation: 1 affiliationInfo: "签署方2" defaultValue:xxx fieldFormat: xxx },{ affiliation: 1 affiliationInfo: "签署方2" defaultValue:xxx fieldFormat: xxx }]
转换二维数组对象
var arrayTwo = Object.values( formList.reduce((res, item) => {
//找到相同的字段 res[item.affiliation] ? res[item.affiliation].push(item) : (res[item.affiliation] = [item]); return res; }, {}) );
console.log(arrayTwo)
结果显示如下:
arrayTwo:[ 0:[
0:{...},
1:{...}
] 1:[ 0:{...},
1:{...}
] ]