This question already has answers here:
Get all unique values in a JavaScript array (remove duplicates)
                                
                                    (85个答案)
                                
                        
                                在11个月前关闭。
            
                    
有什么方法可以通过ES6的1种方法将对象唯一地推入数组?

例如:

MyArray.pushUniquely(x);


还是好用的旧版本之类的? :

MyMethod(x) {

    if ( MyArray.IndexOf(x) === -1 )
        MyArray.Push(x);

}


有什么方法可以通过ES6进行唯一推送?

最佳答案

使用Set集合而不是数组。

07-24 09:51
查看更多