💾arr.removeDuplicates()
Object.defineProperties(Array.prototype, {
// 🔹 .removeDuplicates()
removeDuplicates: {
value: function() {
return [... new Set(this)]; // new array (non-mutating)
},
},
});[ 1, 1, 2, 3, 2, 3, 4 ].randomElement, // (random)
[ 1, 1, 2, 3, 2, 3, 4 ].removeDuplicates(), // [ 1, 2, 3, 4 ]
[1].concat([1,2,3],[2,3,4]), // [ 1, 1, 2, 3, 2, 3, 4 ]
[1].union([1,2,3],[2,3,4]), // [ 1, 2, 3, 4 ]Last updated