Deep unique array element - Node.js Array

Node.js examples for Array:Set Operation

Description

Deep unique array element

Demo Code


Array.prototype.deepUnique = function () {
    var a = {};/*ww  w.  java2s.c  o  m*/
    for (var i = 0, l = this.length; i < l; i++) {
        var hash = JSON.stringify(this[i]);
        if (a[hash] === undefined) {
            a[hash] = this[i];
        }
    }
    return Object.values(a);
}

Related Tutorials