📜  在数组中查找元素并将其替换为回调函数 - 无论代码示例

📅  最后修改于: 2022-03-11 14:59:15             🧑  作者: Mango

代码示例1
var charSets = new Array("ab","bb","cd","ab","cc","ab","dd","ab");

function replaceElement(element,index,array) {
   if (element == "ab") array[index] = "**";

}

// apply function to each array element
charSets.forEach(replaceElement);
alert(charSets); // prints **,bb,cd,**,cc,**,dd,**