js 数组对象去重
let hash = {};
let config = [
{ name: 2, state: true, output: 'Y'},
{ name: 3, state: true, output: 'A'},
{ name: 5, state: true, output: 'S'},
{ name: 7, state: true, output: 'B'}
];
config = [...config, { // 合并数组 ...运算符即为数组展开运算符
name: 3,
state: false,
output: 'A',
}]
const newArr = config.reduce((item, next) => {
console.log('hash--',hash)
console.log('next--',next.name)
console.log('hash[next.name]--',hash[next.name])
hash[next.name] ? '' : hash[next.name] = true && item.push(next);
return item
}, []);
//[{"name":2,"state":true,"output":"Y"},{"name":3,"state":true,"output":"A"},{"name":5,"state":true,"output":"S"},{"name":7,"state":true,"output":"B"}]
js 数组对象去重的更多相关文章
- 【原】js数组对象去重最简单的方法
简单的数组去重是比较简单的,方法也特别多,如给下面的数组去重: let arr = [1,2,2,4,9,6,7,5,2,3,5,6,5] 最常用的可以用for循环套for循环,再用splice删除重 ...
- js数组对象去重
转: https://www.cnblogs.com/gaoht/p/9850449.html 在数组对象中去掉重复的对象: export function deteleObject(obj) { v ...
- js技巧-使用reduce实现更简洁的数组对象去重和数组扁平化
Array.prototype.reduce()方法介绍: 感性认识reduce累加器: const arr = [1, 2, 3, 4]; const reducer = (accumulator, ...
- 判断js数组/对象是否为空
/** * 判断js数组/对象是否为空 * isPrototypeOf() 验证一个对象是否存在于另一个对象的原型链上.即判断 Object 是否存在于 $obj 的原型链上.js中一切皆对象,也就是 ...
- 数组去重----es6&es5&数组对象去重
es6方法: 普通数组: 1.使用Array.from(new Set(arr)); /* * @param oldArr 带有重复项的旧数组 * @param newArr 去除重复项之后的新数组 ...
- JS中数组对象去重
JS数组去重 JS中对数组去重最好不要用unique方法,该方法主要是对dom节点数组的去重,如果对普通的数组元素去重只会去掉与之相邻的重复元素,也就是如果数组中还有不相邻的重复元素存在,将不会被去掉 ...
- js 数组对象的操作方法
在jquery中处理JSON数组的情况中遍历用到的比较多,但是用添加移除这些好像不是太多. 今天试过json[i].remove(),json.remove(i)之后都不行,看网页的DOM对象中好像J ...
- JS数组&对象遍历
遍历的总结,经常用到的,希望帮助你我成长. JS数组遍历: 1,普通for循环 var arr = [1,2,3,4,9]; for ( var i = 0; i <arr.length; i+ ...
- js数组对象排序详解
一.js对象遍历输出的时候真的是按照顺序输出吗? 下边就来实践一下: var obj={'3':'ccc',name:'abc',age:23,school:'sdfds',class:'dfd',h ...
随机推荐
- ansible一键部署LAMP
一.实现ansible跟节点间无密码访问,不会配置的请看 文章 . 二.创建目录 $ mkdir -p playbooks/{files,templates} 三.创建php测试文件index.p ...
- python的语法糖
# -*- coding: utf-8 -*-def deco(func): print("before myfunc() called.") func() print(" ...
- Material使用05 MdListModule模块 MdButtonToggleModule模块
1 在共享模块中导入MdListModule模块 import { NgModule } from '@angular/core'; import { CommonModule } from '@an ...
- 面试题: mysql 数据库去重 已看1 不好使
mysql去重面试总结 前言:题目大概是这样的. 建表: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 CREATE TABLE `test2` ( `id` ...
- c++中Int装string
java中,string类型非常强大,任何类型和string类型相加都变成了string类型.但是c++中string功能就比较少 int转string有两种方式 1:stringstream; ; ...
- try catch 块中debug时发现错误细节的一次记录
在解决已有代码的一个问题时,有一个try catch块,基本代码如下: try { //do something } catch { LogHelper.Debug(typeof(myHelper), ...
- 8. CTF综合靶机渗透(一)
靶机说明 虚拟机难度中等,使用ubuntu(32位),其他软件包有: PHP apache MySQL 目标 Boot to root:从Web应用程序进入虚拟机,并获得root权限. 运行环境 靶机 ...
- Vue packages version mismatch: 版本冲突;Error: EPERM: operation not permitted
1.npm install vue-template-compiler@2.5.3 出现此问题 npm ERR! path G:\XXX.Web\node_modules\fsevents\node_ ...
- 高性能服务器设计(Jeff Darcy's notes on high-performance server design
高性能服务器设计(Jeff Darcy's notes on high-performance server design 我想通过这篇文章跟大家共享一下我多年来怎样开发“服务器”这类应用的一些想法和 ...
- Django 之装饰器实现登录认证
def check_login(func): # 自定义登录验证装饰器 def warpper(request, *args, **kwargs): is_login = request.sessio ...