JavaScript USES loops and splits to replace and delete element instances
- 2020-03-30 04:07:58
- OfStack
The use of looping and splitting to replace and delete elements has been tested to be simple but practical, especially for novice users
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title> Use loops and splits to replace and delete elements </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>