Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

indexof javascript duplicate arrays

Array.prototype.getDuplicates = function () {
    var duplicates = {};
    for (var i = 0; i < this.length; i++) {
        if(duplicates.hasOwnProperty(this[i])) {
            duplicates[this[i]].push(i);
        } else if (this.lastIndexOf(this[i]) !== i) {
            duplicates[this[i]] = [i];
        }
    }

    return duplicates;
};
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #indexof #javascript #duplicate #arrays
ADD COMMENT
Topic
Name
7+8 =