JS deduplication

<#--de-duplicate-->
        Array.prototype.unique = function () {
            var res = [];
            var json = {};
            for (var i = 0; i < this.length; i++) {
                if (!json[this[i]]) { //json does not contain the first value, and put it into json, if it is included, jump out
                    res.push(this[i]); //The value that does not contain is put into res
                    json[this[i]] = 1;  //
                }
            }
            return res;
        }

datas.unique()

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326360000&siteId=291194637