Javascript Array Replace element via forEach()
let 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);// w ww.j av a 2 s . c o m console.log(charSets); // prints **,bb,cd,**,cc,**,dd,**