Javascript Array Replace element by value

Description

Javascript Array Replace element by value


let charSets = new Array("ab","bb","cd","ab","cc","ab","dd","ab");

// replace element
while (charSets.indexOf("ab") != -1) {
   charSets.splice(charSets.indexOf("ab"),1,"**");
}
console.log(charSets); // **,bb,cd,**,cc,dd,**



PreviousNext

Related