将数组对象相同值合并新对象并插入新数组

let data = [
	{
		name: '商品名',
		id: 0,
		order_sn: '12343265253'
	},
	{
		name: '商品名1',
		id: 1,
		order_sn: '12343265253'
	},
	{
		name: '商品名2',
		id: 2,
		order_sn: '12343265252'
	},
	{
		name: '商品名3',
		id: 3,
		order_sn: '12343265252'
	},
]

let list = [];
const order_sn = new Set(data.map(item => item.order_sn));
order_sn.forEach(item => {
  const arr = data.filter(p => p.order_sn === item);
  list.push({ order_sn: item, list: arr });
});

Last Updated:
Contributors: pengrengui