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 3.3k times
19

Peter Mortensen
- 30,738
- 21
- 105
- 131

Paulo Bueno
- 2,499
- 6
- 42
- 68
3 Answers
58
barea = barea.replace(area, "cu")
You need to assign it since String.prototype.replace
isn't a mutator method.

meder omuraliev
- 183,342
- 71
- 393
- 434
-
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
- 643,351
- 109
- 780
- 844