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

Javascript remove custom array deletion method

高洛峰
Release: 2017-01-20 11:04:32
Original
1534 people have browsed it

<html xmlns="http://www.w3.org/1999/xhtml" > 
<head> 
<title>Javascript自定义数组删除方法remove()</title> 
<script type="text/javascript"> 
 Array.prototype.remove=function(dx){ 
   if(isNaN(dx)||dx>this.length){return false;} 
   for(var i=0,n=0;i<this.length;i++){ 
     if(this[i]!=this[dx]){ 
       this[n++]=this[i] 
     } 
   } 
   this.length-=1 
  } 
function f(){ 
var str = "001|002|003";// 
var arr = str.split("|"); 
alert("删除前数组长度:" + arr.length); 
for(var i=0;i<arr.length;i++){ 
alert(arr[i]); 
} 
arr.remove(1);//javascript本来是不包含些函数的。 
alert("删除后数组长度:" + arr.length); 
for(var i=0;i<arr.length;i++){ 
alert(arr[i]); 
} 
} 
</script> 
</head> 
<body> 
<input type="button" onclick="f();" value="ok" /> 
</body> 
</html>
Copy after login

For more articles related to Javascript remove custom array deletion method, please pay attention to the PHP Chinese website!

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!