For now I use the replace method for this but I wanted to know if there is an exclusive method to do this:
pontos = '${parseInt(pontos) + aposta}${pontos.replace(parseInt(pontos), "")}';
For now I use the replace method for this but I wanted to know if there is an exclusive method to do this:
pontos = '${parseInt(pontos) + aposta}${pontos.replace(parseInt(pontos), "")}';
It does not exist, but you can make one. Just add to the prototype of type String
that all strings, both existing and those that will still be instantiated, will have it.
String.prototype.remover = function (input) {
var output = this;
while (output.indexOf(input) > -1) { // só porque o replace não é global.
output = output.replace(input, "");
}
return output;
}
Note that this method does not change the string, but returns a new one.
And to test, after running the above code, you can do in the console:
"abcde".remover("c");