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
WBOYOriginal
2016-05-16 16:34:211174browse

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>

ie8 does not yet support indexOf and splice

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