Answers for "indexof javascript duplicate arrays"

0

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;
};
Posted by: Guest on May-19-2020

Code answers related to "indexof javascript duplicate arrays"

Code answers related to "Javascript"

Browse Popular Code Answers by Language