当前位置:网站首页>js 数组对象中goods_id相同和并一个对象,把goods_size_id值添加一起
js 数组对象中goods_id相同和并一个对象,把goods_size_id值添加一起
2022-07-15 22:43:00 【爱吃鱼的康康】
//数组对象中goods_id相同和并一个对象,把goods_size_id值添加一起
let arr = [
{
goods_id:1,
goods_size_id:22,
},
{
goods_id:2,
goods_size_id:23,
},
{
goods_id:3,
goods_size_id:24,
},
{
goods_id:1,
goods_size_id:25,
},
]
//处理成这种数据
let newArr = [
{
goods_id:1, goods_size_id:[22,25]},
{
goods_id:2, goods_size_id:23},
{
goods_id:2, goods_size_id:24},
]
function mergeArrFn(arr) {
let newArr = [];
arr.forEach(item => {
let dataItem = item;
if (newArr.length > 0) {
let filterValue = newArr.filter(v => {
return v.goods_id == dataItem.goods_id
})
if (filterValue.length > 0) {
newArr.forEach(n => {
if (n.goods_id == filterValue[0].goods_id) {
n.goods_size_id = [filterValue[0].goods_size_id, dataItem.goods_size_id]
}
})
} else {
newArr.push(dataItem)
}
} else {
newArr.push(dataItem)
}
})
return newArr
}
const fd = this.mergeArrFn(arr);
console.log(fd,'fd)

边栏推荐
- With 8 years of product experience, I have summarized these practical experience of continuous and efficient research and development
- 力扣练习——18 前 K 个高频元素
- torch.gather()
- Ethernet development and testing, have you done this step right (1)
- Deep understanding of modern web browsers (3)
- STM32读取双轴遥感的数据值
- IDEA - Could not autowire. No beans of ‘XXXMapper‘ type found.
- Who else can't use the three methods of de duplication in SQL?
- 手机号码11位以及格式验证规则
- Thinking about the research links of data governance projects
猜你喜欢

LeetCode_513_找树左下角的值

Original error was: DLL load failed while importing _ multiarray_ Umath: the specified module cannot be found

(手工)【sqli-labs44、45】POST字符型注入、盲注、堆叠注入

记录一次坑爹内存泄漏排查经历

Reinforcement Learning 强化学习(一)

广西二造备考仅剩1天 二级造价师考前三页纸来了 字字提分

Ethernet development and testing, have you done this step right (1)
[email protected] | Uio-66 / graphene oxide (uio-66 / go) |pt [email protected] |

Uni app - solve the problem that rich text parsing pictures cannot adapt to width and height (pictures exceed the screen width and are uncontrolled)

Stochastic Multiple Choice Learning for Training Diverse Deep Ensembles
随机推荐
2022 mathematical modeling "May Day Cup" question B
Sélection de nouvelles fonctionnalités pour la version PHP - PHP 8.0x
Is it safe to open an account for flush stock
Nc19910 [cqoi2007] rectangular rect
Li Kou daily question - day 38 -58 Length of the last word
Flume 数据采集
1. Mx6u system migration-3-uboot startup process
Seven uncovered industrial 4.0 misunderstandings
Stochastic Multiple Choice Learning for Training Diverse Deep Ensembles
Deep learning for Human Strategic Behaviour
传输层 ------ UDP
超好用的截图软件Snipaste(包含安装包)、如何设置Snipaste开机自启
Fan in and fan out mode of asynchronous API design
信息系统项目管理师必背核心考点(四十三)预期货币价值(EMV)
(手工)【sqli-labs44、45】POST字符型注入、盲注、堆叠注入
Design of user integral function
Thinking about the research links of data governance projects
无心剑中译迈克尔《代数的定义》
Heartless sword Chinese translation of Michael's definition of algebra
PHP版本新特性摘选 - PHP5.6.X