码迷,mamicode.com
首页 > 编程语言 > 详细

js数组去重

时间:2017-07-25 00:58:37      阅读:291      评论:0      收藏:0      [点我收藏+]

标签:alt   console   com   turn   length   ges   png   检索   func   

技术分享

function unique(array){
  var n=[]; //新的临时数组
  for(var i=0;i<array.length;i++){
    if(n.indexOf(array[i]) == "-1"){     //检索值为-1代表不存在
      n.push(array[i]);        //新数组中不存在此值那么就把它放到新数组中
    }
  }
  return n;
}
var aa=["胡歌","刘恺威","胡歌","靳东","霍建华","靳东"];
console.log(aa)
var bb=unique(aa);
console.log(bb)

js数组去重

标签:alt   console   com   turn   length   ges   png   检索   func   

原文地址:http://www.cnblogs.com/lanlanJser/p/7231727.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!