当前位置:网站首页>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 :
边栏推荐
- Microcomputer principle and interface technology
- Remote desktop connection error
- CUB_ Visualization of key points in 200 bird dataset
- Typescript from introduction to proficiency (XXIV) using import syntax
- RHCE's at, crontab's basic operations, the Chrony service, symmetric encryption and asymmetric encryption
- Ssl== certificate related concepts
- Arrow function of new features of ES6
- 【redis系列】字符串数据结构
- LVS+KeepAlived高可用部署实战应用
- The latest second edition of comic novels, listening to books, three in one, complete source code / integrated visa free interface / building tutorials / with acquisition interface
猜你喜欢

(newcoder 15079) irrelevant (inclusion exclusion principle)

Excel拼接数据库语句

【BGP】小型实验

Process tracking of ribbon principle

数据挖掘——关联分析例题代码实现(下)

How to understand clock cycle and formula CPU execution time = number of CPU clock cycles / dominant frequency

Solve the problem of garbled code when opening the project code in idea

Alibaba Font Icon Library Usage and update methods

The latest second edition of comic novels, listening to books, three in one, complete source code / integrated visa free interface / building tutorials / with acquisition interface

Deep into C language (1) -- operators and expressions
随机推荐
Inclusion exclusion principle
Lucifer 98 life record ing
Division of data link layer, protocols used in data link layer and detailed introduction
谁能详细说下mysqlRC下的半一致读和怎么样减少死锁概率?
MOS tube - rapid recovery application notes (II) [parameters and applications]
从2019 年开始,你一定停止使用了这个营销策略…
RTP send and receive h265
Since 2019, you must have stopped using this marketing strategy
Simple understanding of Poe and UPS Technology
Casbin入门
Shopify seller: EDM marketing should be combined with salesmartly to easily get the conversion rate
Opensql quick learning
座机的表单验证
关于双指针的思想总结
【BGP】小型实验
Form verification of landline
Why does the 20 bit address bus determine the storage space of 1MB
Big manufacturers finally can't stand "adding one second", and companies such as Microsoft, Google meta propose to abolish leap seconds
JS cookie usage
Configmap configuration and secret encryption