string[index] = 'a'
seems didn't work, it cannot change the string. Why's that and are there any articles about this?
string[index] = 'a'
seems didn't work, it cannot change the string. Why's that and are there any articles about this?
here an example of a function that would solve this
function replaceAt(string, index, newValue) {
if(index >= string.length || index < 0) {return false;}
var start = string.substr(0,index);
var finish = string.substr(index+1);
return start + newValue.toString() + finish;
}
Strings are not arrays but you can convert them into arrays and then join them back into strings.
var strArray = string.split("");
strArray[index] = 'a';
string = strArray.join("");