ES6 Set All In One
ES6 Set All In One
Set 集合
Map 字典/地图
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
Set
数组去重
const arr = [1, 2, 3, 3, 2, 1];
const unique = [...new Set(arr)];
// [1, 2, 3]
const arr = [1, 2, 3, 3, 2, 1];
// unique = arr.reduce((acc, item) => !acc.includes(item) ? acc.concat([item]) : acc, []);
const unique = arr.reduce((acc, item) => {
if(!acc.includes(item)) {
acc.push(item);
}
return acc;
}, []);
// [1, 2, 3]
refs
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/13997536.html
未经授权禁止转载,违者必究!