每天CookBook之JavaScript-024
- 数组forEach的使用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>024</title>
</head>
<body>
</body>
<script type="text/javascript">
var charSets = ["ab","bb","cd","ab","cc","ab","dd","ab"];
function replaceElement(element,index,array) {
(element == "ab") && (array[index] = "**");
}
charSets.forEach(replaceElement);
console.log(charSets);
</script>
</html>