六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 32|回复: 0

两种常用的javascript数组去重 方法

[复制链接]

升级  46%

37

主题

37

主题

37

主题

秀才

Rank: 2

积分
119
 楼主| 发表于 2012-12-22 21:14:00 | 显示全部楼层 |阅读模式
<div id="cnblogs_post_body">第一种是比较常规的方法

思路:
1.构建一个新的数组存放结果
2.for循环中每次从原数组中取出一个元素,用indexOf查找新数组中是否有该元素
3.若没有,则存到结果数组中

<div id="highlighter_465816" class="syntaxhighlighter" style="margin: 1em 0px !important; padding: 0px !important; border: 1px solid #e0e0e0 !important; outline: 0px !important; background-image: none !important; background-color: #ffffff !important; text-align: left; float: none !important; vertical-align: baseline !important; position: relative !important; left: auto !important; top: auto !important; right: auto !important; bottom: auto !important; height: auto !important; width: 633.5833129882813px; line-height: 1.1em !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-weight: normal; font-style: normal; font-size: 14px; direction: ltr !important; color: #555555; font-variant: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-position: initial initial !important; background-repeat: initial initial !important;"><div class="lines" style="margin: 0px !important; padding: 0px !important; border: 0px !important; outline: 0px !important; background-image: none !important; text-align: left !important; float: none !important; vertical-align: baseline !important; position: static !important; left: auto !important; top: auto !important; right: auto !important; bottom: auto !important; height: auto !important; width: auto !important; line-height: 1.1em !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-weight: normal !important; font-style: normal !important; font-size: 1em !important; direction: ltr !important; background-position: initial initial !important; background-repeat: initial initial !important;"><div class="line alt1" style="margin: 0px !important; padding: 0px !important; border: 0px !important; outline: 0px !important; background-image: none !important; background-color: #ffffff !important; text-align: left !important; float: none !important; vertical-align: baseline !important; position: static !important; left: auto !important; top: auto !important; right: auto !important; bottom: auto !important; height: auto !important; width: auto !important; line-height: 1.1em !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-weight: normal !important; font-style: normal !important; font-size: 1em !important; direction: ltr !important; background-position: initial initial !important; background-repeat: initial initial !important;">
01Array.prototype.unique1 = function(){
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表