function areaMe(area) {
var barea = $('#barea').val();
if (barea.indexOf(area) != -1) {
alert ("..." + barea + "..." + area + "...");
barea.replace(area, "cu"); // Remove
alert ("..." + barea + "..." + area + "...");
}
else {
barea += area + ' '; // Include.
}
$('#barea').val(barea);
}
Asked
Active
Viewed 2.9k times
19
Peter Mortensen
- 30,030
- 21
- 100
- 124
Paulo Bueno
- 2,469
- 5
- 41
- 68
3 Answers
57
barea = barea.replace(area, "cu")
You need to assign it since String.prototype.replace isn't a mutator method.
meder omuraliev
- 177,923
- 69
- 381
- 426
-
3Why doesn't the [MDN page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) mention this? – doABarrelRoll721 Feb 24 '16 at 06:33
-
o gosh thanks hehehe – Diogo Garcia May 03 '18 at 21:08
9
You need to assign the replaced value back to your variable:
barea = barea.replace(area, "cu");
Gumbo
- 620,600
- 104
- 758
- 828