当前位置:网站首页>Object array merges elements according to a field
Object array merges elements according to a field
2022-07-29 03:50:00 【1 Jiajia Jiajia】
Such as :
// arr Is the initial array ,key For what needs to be dealt with key name
unique (arr, key) {
var tempArr = []
var newArr = []
for (let i = 0; i < arr.length; i++) {
if (tempArr.indexOf(arr[i][key]) === -1) {
newArr.push({
name: arr[i].name,
activity: arr[i].activity
})
tempArr.push(arr[i][key]);
} else {
for (let j = 0; j < newArr.length; j++) {
if (newArr[j][key] == arr[i][key]) {
newArr[j].activity = newArr[j].activity.concat(arr[i].activity)
}
}
}
}
return newArr
}
Output :
边栏推荐
- Connect with third-party QQ login
- Instance setup flask service (simple version)
- In depth C language (2) -- definition and use of structure
- What you see and think in Microsoft
- Ssl== certificate related concepts
- What have I learned from 200 machine learning tools?
- 3.解决Pycharm报错Unresolved reference ‘selenium‘ Unresolved reference ‘webdriver‘
- Code ~ hide or disable the status bar and virtual keys
- I.MX6U-驱动开发-2-LED驱动
- Ribbon principle analysis namedcontextfactory
猜你喜欢

1985-2020(8个版次)全球地表覆盖下载与介绍

I.MX6U-驱动开发-2-LED驱动

Alibaba Font Icon Library Usage and update methods

Android view system and custom view Series 1: (kotlin version)

SSL==证书相关概念

面试必备!TCP协议经典十五连问!

UCOS task switching process

容斥原理

Uni app internationalization

Deep into C language (3) -- input and output stream of C
随机推荐
《陌路曾相逢》夏陌沈疏晏_夏陌沈疏晏最新章节
"Strangers once met" Summer Street Shen Shuyan_ Xia Mo Shen Shuyan's latest chapter
向日葵远程控制为何采用BGP服务器?自动最优路线、跨运营商高速传输
数据挖掘——关联分析例题代码实现(下)
LDP --- 标签分发协议
谁能详细说下mysqlRC下的半一致读和怎么样减少死锁概率?
企业网的三层架构
Common methods of lodash Library
First ALV program 2
Kotlin companion object vs global function
Flutter 启动白屏
Configmap配置与Secret加密
(nowcoder22529c) diner (inclusion exclusion principle + permutation and combination)
1. Header file - Comment - namespace - standard input / output stream
Alibaba Font Icon Library Usage and update methods
The data type of symbol, a new feature of ES6
Why does the 20 bit address bus determine the storage space of 1MB
Analysis of new retail o2o e-commerce model
Remote desktop connection error
With more than 5 years of work experience and a salary of 15K, would you accept it if you were me?