I need to check a JavaScript array to see if there are any duplicate values. What\'s the easiest way to do this? I just need to find what the duplicated values are - I don\'
Following logic will be easier and faster
// @Param:data:Array that is the source
// @Return : Array that have the duplicate entries
findDuplicates(data: Array): Array {
return Array.from(new Set(data)).filter((value) => data.indexOf(value) !== data.lastIndexOf(value));
}
Advantages :
Description of Logic :
Note: map() and filter() methods are efficient and faster.