I need a solution to find values that appear more than once in an array. The current code I have is quite complex.
var arr = [1, 2, 3, 4, 2, 3];
var flag = {}
var exist2arr = [];
for(var i = 0; i < arr.length; i++){
for(var j = 0 ; j < arr.length; j ++){
if(i !=j && arr[i] == arr[j]){
if(!flag[arr[i]])
exist2arr.push(arr[i]);
flag[arr[i]] = 1;
}
}
}
console.log(exist2arr);
Is there a simpler way (using a built-in JavaScript function) to achieve this? Any suggestions would be greatly appreciated.