Answers for "find element in an array and replace it by a callback function"

0

find element in an array and replace it by a callback function

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,**
Posted by: Guest on May-12-2021

Code answers related to "find element in an array and replace it by a callback function"

Browse Popular Code Answers by Language