美文网首页
js 数组对象去重

js 数组对象去重

作者: 李大嘴JimmyLee | 来源:发表于2020-05-07 09:38 被阅读0次
          unique(arr, type) {
            if (arr.length === 0) {
              return arr;
            } else {
              if (type) {
                const obj = {};
                const newArr = arr.reduce((cur, next) => {
                  obj[next[type]] ? '' : obj[next[type]] = true && cur.push(next);
                  return cur;
                }, []);
                return newArr;
              } else {
                return Array.from(new Set(arr));
              }
            }
          }

相关文章

网友评论

      本文标题:js 数组对象去重

      本文链接:https://www.haomeiwen.com/subject/lploghtx.html