es6 unique array of objects with set

前端 未结 3 1349
傲寒
傲寒 2020-12-11 15:21

I came across this example for creating unique arrays with es6

[ ...new Set(array) ]

Which seems to work fine until I tried it with an arra

3条回答
  •  独厮守ぢ
    2020-12-11 15:42

    Why is that ?

    As per documentation

    The Set object lets you store unique values of any type, whether primitive values or object references.

    Now reference for each of those arrays inside that Set constructor will be different so they are not considered to be a unique value by the constructor.

提交回复
热议问题