每天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>
posted @ 2016-07-10 20:15  4Thing  阅读(92)  评论(0编辑  收藏  举报