I have this code :
widget-ads-120-240[3][link-100]
I want to change "100" with js. maybe 100 is 5 or 1 . it's an id.
I have this one too
widget-ads-120-240-3-link-1
I need two or one code for these .
I have this code :
widget-ads-120-240[3][link-100]
I want to change "100" with js. maybe 100 is 5 or 1 . it's an id.
I have this one too
widget-ads-120-240-3-link-1
I need two or one code for these .
String.prototype.replaceAt = function(index, character) {
return this.substr(0, index) + character + this.substr(index + character.length);
}
'widget-ads-120-240-3-link-100'.replaceAt('widget-ads-120-240-3-link-100'.lastIndexOf('-') + 1, '200');
replaceAt taken from https://stackoverflow.com/a/1431113/2025923
try:
'widget-ads-120-240[3][link-100]'.replace(/(link-)[0-9]*/,'$1'+the_change_value)