I'm still getting the hang of JavaScript and I'm attempting to update array elements using regex that match specific strings. Below is a snippet of code I've been working on:
<button onclick="myFunction()">Click Here</button>
<p id="demo"></p>
<script>
function myFunction() {
var abc = ["deno", "eno","pqr","lenovo"];
var i, text = "";
for(i = 0; i < abc.length; i++) {
text += abc[i].replace(/no/i, "po");
document.getElementById("demo").innerHTML = text;
}
}
</script>
My goal is to replace any array element containing "no" with "po."
This is what I am aiming for:
abc["depo","epo","pqr","lepovo"]