js多个数组交叉合并

2024年07月24日 建站教程

var arr1 = [
	{userId: 1, name:'清北'},
	{userId: 2, name:'浙京'}
]
var arr2 = [
	{role: "1", group: "3"},
	{role: "1", group: "2"}
]

//输出结果
console.log(arr2.map(z=>arr1.map(x=>({...x, ...z}))).flat())
//0: {userId: 1, name: '清北', role: '1', group: '3'}
//1: {userId: 2, name: '浙京', role: '1', group: '3'}
//2: {userId: 1, name: '清北', role: '1', group: '2'}
//3: {userId: 2, name: '浙京', role: '1', group: '2'}

本文链接:http://so.lmcjl.com/news/9082/

展开阅读全文
相关内容