Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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,**
Source by www.oreilly.com #
 
PREVIOUS NEXT
Tagged: #find #element #array #replace #callback #function
ADD COMMENT
Topic
Name
3+1 =