Skip to content Skip to sidebar Skip to footer

Simple Javascript Replace Not Working

This seems so simple and trivial but it is not working. Here is my javascript: var url = '/computers/'; console.log(url); url.replace(/\//gi, ' '); console.log(url); And here is t

Solution 1:

url = url.replace(/\//gi, " ");

Solution 2:

Nothing changes because you're not assigning the result of the replacement to a variable. Add url = url.replace()

Solution 3:

url.replace(/\//gi, " "); returns the resulting string (in javascript you can't modify an existing string), you are not assigning it to anything

assign it like so:

url = url.replace(/\//gi, " ");

Post a Comment for "Simple Javascript Replace Not Working"