check if array contains duplicates js code example
Example 1: check for duplicates in array javascript
[1, 2, 2, 4, 3, 4].filter((e, i, a) => a.indexOf(e) !== i) // [2, 4]
Example 2: js check if array of objects contains duplicates
const arrayOfObjCopy = [...arrayOfObj];
Object.keys(arrayOfObjCopy).forEach((key) => {
arrayOfObjCopy[key] = JSON.stringify(arrayOfObjCopy[key]);
});
const arrayOfObjhasDuplicates = uniq(arrayOfObjCopy).length != arrayOfObjCopy.length;