I am trying to write a jquery $.each() function that takes in an array and puts the duplicates from that array into another array. I know how to do it using a for loop as seen below, but can't seem to figure it out in an $.each function. Any help would be appreciated. Thanks.
$.duplicates = function(arr) {
dup = [];
for (var i = 0; i < arr.length; i++){
for (var j = i + 1; j < arr.length; j++){
if (arr[i] === arr[j]){
dup.push(arr[i]);
}
}
}
return dup;
};