I have a line as follows:
var str = "a,b,c,a,e,f";
I need to replace the last element, separated by commas, with another.
ie, str = "a,b,c,a,e,anystring";
I did this with a method splitand added it to create a new line. But it does not work as expected
What I did as follows:
var str = "a,b,c,d,e,f";
var arr = str.split(',');
var res = str.replace(arr[5], "z");
alert(res);
Is there any regex?
source
share