Home > Web Front-end > JS Tutorial > JavaScript uses loops and splits to replace and delete element instances_javascript tips

JavaScript uses loops and splits to replace and delete element instances_javascript tips

WBOY
Release: 2016-05-16 16:34:21
Original
1172 people have browsed it

Use loops and splits to replace and delete elements. It has been tested to be simple but very practical, especially suitable for novice friends

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

ie8 does not yet support indexOf and splice

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