我有以下内容:
$(function () {
var list = ["/62","/15","/65","/62","/15","/08","/01","/65","/62","/65","/62","/15","/01"];
$.unique(list);
console.log(list);
});
输出结果为:
["/01", "/65", "/62", "/65", "/08", "/15"]
https://api.jquery.com/jquery.unique/说:
The $.unique() function searches through an array of objects, sorting the array, and removing any duplicate nodes.
两个“/ 65”是否被认为是不同的?如果是这样,为什么:
$(function () {
var list = ["/62","/15","/65","/62","/15","/08","/01","/65","/62","/65","/62","/15","/01"];
$.unique(list);
$.unique(list);
console.log(list);
});
产生
["/15", "/08", "/62", "/65", "/01"]
为什么以“/ 0”开头的那些不在输出的开头?
答案 0 :(得分:0)
正如你可以从长评论帖中猜测的那样,使用$.unique
是错误的。相反,请使用Underscore的_.uniq
。