It seems that you do not want to find duplicates, only to find out if they are?
You are pretty close, the function works here
var hasDuplicates = function (arr) { var _store = {}; for (var i = 0; i < arr.length; i++) { if (typeof _store["_" + arr[i]] !== "undefined") { return true; } _store["_" + arr[i]] = true; } return false; };
Underscore characters in an associative array are needed to store numeric values. The hasDuplicates() function only works with objects that have the toString() method.
Check for duplicates;
var yourArray = [1, 5, 7, 3, 5, 6]; if (hasDuplicates(yourArray)) {...
BjΓΆrn
source share