I have to get a list of values that exist more than once in an array. This is current code , but as you can see it's too complicated.
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 any other way (simple code using javascript built-in function) to achieve this? Any kind of help appreciate.