Home  >  Article  >  Web Front-end  >  javascript 删除数组中重复值的几种方法介绍

javascript 删除数组中重复值的几种方法介绍

WBOY
WBOYOriginal
2016-06-01 09:54:291116browse

具体方法请看下面代码,每种方法都附带了解释,大家可以自己在本网站的在线代码调试工具中运行一下每种方法。

<code class="language-javascript">/*方法一: 1,'1' 会被认为是相同的; 所有hash对象,如:{x;1},{y:1}会被认为是相同的 //10ms */
Array.prototype.unique=function(){
  var newArr=[],obj={};
  for(var i=0,len=this.length;i<len if newarr.push obj return newarr array.prototype.unique="function(){" var for i="0,len=this.length;i<len;i++){" j="i+1,len=newArr.length;j<len;j++)" newarr.splice j-- len arr0='[11,21,221,13,24,"134","1",{x:1,y:1},{name:"pobaby",age:"12",hobby:"football"},{name:"pobaby1",age:"121",hobby:"football1"}];' arr="[],num;" num="Math.floor(Math.random()*50);" arr.push t1="new" date console.log arr.unique t2="new"></len></code>

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn