Javascript Array hasDuplicates()

Description

Javascript Array hasDuplicates()

//http://stackoverflow.com/questions/19655975/check-if-an-array-contains-duplicate-values
Array.prototype.hasDuplicates = function() {
    this.sort();/*from  www .ja v a  2s .  c o  m*/
    for (var i = 1; i < this.length; i++) {
        if (this[i - 1] == this[i]) {
            return true;
        }
    }
    return false;
};



PreviousNext

Related