let arr = [2, 5, 3, 3, 5, 7, 3, 7, 3, 7, 2, 2] // (1)拓展运算符 + new Set 方法 let narr1 = [...new Set(arr)] // (2)Array.from + new Set 方法 let narr2 = Array.from(new Set(arr)) // (3)new Map() + filter方法 let myMap = new Map() let narr3 = arr.filter((item) => { return !myMap.has(item) && myMap.set(item, 1) })
相关es6知识点 new Map() new Set() Array.form()
解构
// (4)for循环方法 let narr2 = [] arr.forEach((item) => { if(narr2.indexOf(item) == -1) { narr2.push(item) } })
标签:ES6,arr,Set,narr2,item,let,数组,new From: https://www.cnblogs.com/Esther-yan/p/17074351.html