JSFiddle - React, Tailwind, and code Playground

by Khalil Zhang

JavaScript

// Add a ‘unique 'method for Array object for producing a duplicate-free version of the array. Here is one sample:  [1, 2, 3, 1].unique();  -> [1, 2, 3]

Array.prototype.unique = function(){
    var temp = [];
    for(var i = 0, j = this.length; i < j; i++){
        var a = this[i];
        if(temp.indexOf(a) === -1)
            temp.push(a);
    }
    return temp;
}

var list = [3,2,3,1];
alert(list.unique().join(','));