Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2561203
  • 博文数量: 245
  • 博客积分: 4125
  • 博客等级: 上校
  • 技术积分: 3113
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-25 23:56
文章分类

全部博文(245)

文章存档

2015年(2)

2014年(26)

2013年(41)

2012年(40)

2011年(134)

2010年(2)

分类: JavaScript

2013-07-02 17:42:58

参考:

方法一:

点击(此处)折叠或打开

  1. a = ["Mike","Matt","Nancy","Adam","Jenny","Nancy","Carl",1,2,3,1,2,3,4,5,6,7,8,1,2,3];
  2. b = {};
  3. for (var i = 0; i < a.length; i++) {
  4.     b[a[i]] = a[i];
  5. }
  6. c = [];
  7. for (var key in b) {
  8.     c.push(key);
  9.     console.log(key);
  10. }

方法二:

点击(此处)折叠或打开

  1. myArray = ["Mike","Matt","Nancy","Adam","Jenny","Nancy","Carl",1,2,3,1,2,3,4,5,6,7,8,1,2,3];
  2. uniqueArray = myArray.filter(function(elem, pos) {
  3.     return myArray.indexOf(elem) == pos;
  4. });
  5. console.dir(uniqueArray);

方法三(jquery):

点击(此处)折叠或打开

  1. var names = ["Mike","Matt","Nancy","Adam","Jenny","Nancy","Carl"];
  2. var uniqueNames = [];
  3. $.each(names, function(i, el){
  4.     if($.inArray(el, uniqueNames) === -1) uniqueNames.push(el);
  5. });



阅读(1501) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~