当前位置:网站首页>js中的数组对象
js中的数组对象
2022-06-27 09:14:00 【Xiaaoke】
数组对象去重
根据数组对象的一个字端来判断去重
- 参数
- arr:要去重的数组(数组对象)
- id:根据去重字端名称(string)
- 返回值:合并后的数组对象(数组对象)
function arrObjUniq(arr, id){
let obj = {
};
arr = arr.reduce((cur, next)=>{
obj[next[id]] ? '' : obj[next[id]] = true && cur.push(next);
return cur;
})
return arr;
}
数组对象相同合并
根据数组对象的一个字端来判断合并
- 参数
- object:目标对象(数组对象)
- sources:来源对象(数组对象)
- id:根据合并字端(string)
- 返回值:合并后的数组对象(数组对象)
function objMerge(object,sources,id){
const c = [];
object.forEach(item=>
sources(val => item[id] === val[id] && c.push({
...item, ...val}))
);
return c;
}
数组对象分组
const groups = dataObj.reduce((ini, product) => {
const [targetGroup] = ini.filter((grp) => {
const [first] = grp;
return first.grade === product.grade;
});
if (targetGroup) targetGroup.push(product)
else ini.push([product]);
return ini;
}, []);
边栏推荐
- SVN版本控制器的安装及使用方法
- This, constructor, static, and inter call must be understood!
- RMAN-08137 主库无法删除归档文件
- 静态代码块Vs构造代码块
- vim 从嫌弃到依赖(20)——global 命令
- 2022.6.26-----leetcode. seven hundred and ten
- June 26, 2022 (LC 6100 counts the number of ways to place houses)
- Markem Imaje Marken IMAS printer maintenance 9450e printer maintenance
- That is, a one-stop live broadcast service with "smooth live broadcast" and full link upgrade
- 初步认识pytorch
猜你喜欢

RMAN-08137 主库无法删除归档文件

Rough reading DS transunet: dual swing transformer u-net for medical image segmentation

E+h secondary meter repair pH transmitter secondary display repair cpm253-mr0005

Understand neural network structure and optimization methods

MATLAB小技巧(18)矩阵分析--熵权法

(original) custom drawable

Installation and use of SVN version controller

Matlab tips (18) matrix analysis -- entropy weight method

隐私计算FATE-离线预测

经典的一道面试题,涵盖4个热点知识
随机推荐
Chapter 11 signal (I) - concept
Matlab tips (19) matrix analysis -- principal component analysis
Quelques exercices sur les arbres binaires
微信小程序学习之五种页面跳转方法.
Introduction to websocket protocol
Enumeration? Constructor? Interview demo
Analysis of orthofinder lineal homologous proteins and result processing
E+h secondary meter repair pH transmitter secondary display repair cpm253-mr0005
使线程释放锁资源的操作/方法重载一点注意事项
Quick start CherryPy (1)
CLassLoader
经典的一道面试题,涵盖4个热点知识
视频文件太大?使用FFmpeg来无损压缩它
Digital ic-1.9 understands the coding routine of state machine in communication protocol
ThreadLocal再次挖掘它的知识点
vim 从嫌弃到依赖(20)——global 命令
HiTek电源维修X光机高压发生器维修XR150-603-02
Semi-supervised Learning入门学习——Π-Model、Temporal Ensembling、Mean Teacher简介
How much do you know about the cause of amplifier distortion?
快捷键 bug,可复现(貌似 bug 才是需要的功能 [滑稽.gif])