How to split a comma separated string and process in a loop using JavaScript?
How to split a comma separated string and process in a loop using JavaScript?
Please run below code may it helps you :)
var str = "this,is,an,example";
var strArr = str.split(',');
var data = "";
for(var i=0; i<strArr.length; i++){
data += "Index : "+i+" value : "+strArr[i]+"<br/>";
}
document.getElementById('print').innerHTML = data;
<div id="print">
</div>
you can Try the following snippet:
var str = "How are you doing today?";
var res = str.split("o");
console.log("My Result:",res)
and your output like that
My Result: H,w are y,u d,ing t,day?