复制代码 代码如下:
function unique(data){
data = data || [];
var a = {};
for (var i=0; i<data.length; i++) {
var v = data[i];
if (typeof(a[v]) == 'undefined'){
a[v] = 1;
}
};
data.length=0;
for (var i in a){
data[data.length] = i;
}
return data;
}
function test(){
var arr = [9,1,3,8,7,7,6,6,5,7,8,8,7,4,3,1];
var arr1 = unique(arr);
alert(arr1.join(","));
}
test();
function unique(data){
data = data || [];
var a = {};
for (var i=0; i<data.length; i++) {
var v = data[i];
if (typeof(a[v]) == 'undefined'){
a[v] = 1;
}
};
data.length=0;
for (var i in a){
data[data.length] = i;
}
return data;
}
function test(){
var arr = [9,1,3,8,7,7,6,6,5,7,8,8,7,4,3,1];
var arr1 = unique(arr);
alert(arr1.join(","));
}
test();
标签:
数组,去除重复元素
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com
暂无“js 高效去除数组重复元素示例代码”评论...