当前位置:网站首页>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;
}, []);
边栏推荐
- The markdown plug-in of the browser cannot display the picture
- Improving efficiency or increasing costs, how should developers understand pair programming?
- VIM from dislike to dependence (20) -- global command
- 不会初始化类的几种Case
- Brief introduction to SSL encryption process
- Quick start CherryPy (1)
- Today's three interviews demo[integer ASCII class relationship]
- 力扣84柱状图中最大的矩形
- 快捷键 bug,可复现(貌似 bug 才是需要的功能 [滑稽.gif])
- 2022.06.26(LC_6100_统计放置房子的方式数)
猜你喜欢
![[cloud native] 2.3 kubernetes core practice (Part 1)](/img/f8/dbd2546e775625d5c98881e7745047.png)
[cloud native] 2.3 kubernetes core practice (Part 1)

Improving efficiency or increasing costs, how should developers understand pair programming?

Advanced mathematics Chapter 7 differential equations

Preliminary understanding of pytorch

Quelques exercices sur les arbres binaires

ucore lab5

Analysis of orthofinder lineal homologous proteins and result processing

Rockermq message sending and consumption mode

Markem imaje马肯依玛士喷码机维修9450E打码机维修

最全H桥电机驱动模块L298N原理及应用
随机推荐
ThreadLocal再次挖掘它的知识点
Five page Jump methods for wechat applet learning
VIM from dislike to dependence (19) -- substitution
内存泄露的最直接表现
ucore lab4
Improving efficiency or increasing costs, how should developers understand pair programming?
Design of a solar charge pump power supply circuit
MYSQL精通-01 增删改
There is no doubt that this is an absolutely elaborate project
三道基础面试题总结
webrtc入门:12.Kurento下的RtpEndpoint和WebrtcEndpoint
多個類的設計
Semi-supervised Learning入门学习——Π-Model、Temporal Ensembling、Mean Teacher简介
【mysql篇-基础篇】通用语法1
Demand visual Engineer
See how much volatile you know
(original) custom drawable
[MySQL basic] general syntax 1
std::memory_ order_ seq_ CST memory order
[cloud native] 2.3 kubernetes core practice (Part 1)