check if all values in array are unique javascript code example
Example 1: javascript check if array has duplicates
function hasDuplicates(array) {
return (new Set(array)).size !== array.length;
}
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;