当前位置:网站首页>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;
}, []);
边栏推荐
- I'm almost addicted to it. I can't sleep! Let a bug fuck me twice!
- Internal class ~ lock ~ access modifier
- [diffusion model]
- Brief introduction to SSL encryption process
- Enumeration? Constructor? Interview demo
- MySQL proficient-01 addition, deletion and modification
- Apache POI的读写
- June 26, 2022 (LC 6100 counts the number of ways to place houses)
- webrtc入门:12.Kurento下的RtpEndpoint和WebrtcEndpoint
- E+h secondary meter repair pH transmitter secondary display repair cpm253-mr0005
猜你喜欢

微信小程序学习之五种页面跳转方法.

(original) custom drawable

Imx8qxp DMA resources and usage (unfinished)

The largest rectangle in the bar graph of force buckle 84

That is, a one-stop live broadcast service with "smooth live broadcast" and full link upgrade

Markem Imaje Marken IMAS printer maintenance 9450e printer maintenance

C# 解决使用SQLite 的相对路径问题

Nosql 数据库 -Redis 安装

Some exercises about binary tree

vim 从嫌弃到依赖(19)——替换
随机推荐
std::memory_order_seq_cst内存序
Parameters argc and argv of main()
多个类的设计
One week's experience of using Obsidian (configuration, theme and plug-in)
vim 从嫌弃到依赖(19)——替换
June 26, 2022 (LC 6100 counts the number of ways to place houses)
Conception de plusieurs classes
Analysis of orthofinder lineal homologous proteins and result processing
Markem Imaje Marken IMAS printer maintenance 9450e printer maintenance
IO管脚配置和pinctrl驱动
2022.06.26(LC_6101_判断矩阵是否是一个 X 矩阵)
Installation and usage of source insight tool
ucore lab3
[MySQL basic] general syntax 1
Win10 add right-click menu for any file
HiTek电源维修X光机高压发生器维修XR150-603-02
初步认识pytorch
The markdown plug-in of the browser cannot display the picture
MYSQL精通-01 增删改
MySQL proficient-01 addition, deletion and modification