Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-06-01 09:54:29
Original
1122 people have browsed it

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

<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>
Copy after login

 

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!