使用循环和分割来替换和删除元素,经测试很简单,但很实用,特别适合新手朋友

<!DOCTYPE> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>使用循环和分割来替换和删除元素</title> 
<script> 
var arr = new Array("ab","aa","bc","ab","ss","ab","ss","dd","ab","aa","aa","aa"); 
while(arr.indexOf("ab") != -1){ 
console.log("1"+arr); 
arr.splice(arr.indexOf("ab"),1,"**"); 
} 
console.log(arr); 
while(arr.indexOf("**") != -1){ 
console.log(arr); 
arr.splice(arr.indexOf("**"),1); 
} 
console.log(arr); 
</script> 
</head> 

<body> 
</body> 
</html>

ie8还不支持indexOf和splice

标签:
循环,分割,替换,删除

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com