![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
ES6
zlting~
向上的道路从不拥挤~
展开
-
ES6判断数组是否存在重复元素
ES6判断数组是否存在重复元素new Set 去重后,判断数组长度与原来是否相等let arr = [1,2,3,4,5];if(new Set(arr).size !== arr.length){ alert(存在相同的元素);}原创 2020-12-31 12:37:15 · 2547 阅读 · 0 评论 -
es6循环对象
展示效果数据let obj = { '术语库': 5412, '知识库': 3921, '语料库': 851392, '语音库': 59532}// 数据转换Object.keys(res.data).map(key => { this.fourData.push({ title: key, count: res.data[key] }) })原创 2020-12-10 16:23:21 · 4150 阅读 · 0 评论 -
forEach循环两个数组对象,并添加属性赋值
let arr1 = [ { name: "集合", category: "大数据基础" }, { name: "类", category: "大数据技术" }, { name: "形式化", category: "大数据标准" }]let arr2 = [ { name: "大数据基原创 2020-10-14 13:45:21 · 4798 阅读 · 0 评论 -
js给数组中的对象添加新属性--Object.assign(target,...sources)
Object.assign() 方法用于将所有可枚举属性的值从一个或多个源对象复制到目标对象。它将返回目标对象。const arr = [ { name:'张三', age: 18 }, { name:'李四' , age: 20}, { name:'张三', age: 21 },]let newArr = arr.map((item,index) => Object.assign(item,{id: index + 1}))console.原创 2020-10-14 10:14:16 · 1919 阅读 · 0 评论 -
数组去重,数组中对象去重,根据数组中对象的某个属性去重
数组去重arr = [1,1,3,2,2,4,5,6,6,1,7]以下三种方法可去重new Set(arr)arr.filter((item,index) => arr.indexOf(item) === index)arr.reduce((unique,item)=> unique.includes(item) ? unique : [...unique,item],[])原创 2020-10-13 16:53:32 · 5720 阅读 · 1 评论 -
[ES6]js数组去重——利用 ES6的set 方法
利用Array.from将Set结构转换成数组let arr = Array.from(new Set([0,0,1,2,3,3]))console.log(arr);// (4) [0, 1, 2, 3]Set数据结构,它类似于数组,其成员的值都是唯一的let arr = new Set([0,0,1,2,3,3])console.log(arr);// Set(4) {0, 1, 2, 3}...原创 2020-07-13 09:52:07 · 491 阅读 · 0 评论