0

I am trying to replace:

The quick fox jumped over "tree"

with:

The quick fox jumped over "wall"

I have tried this:

var str = 'The quick fox jumped over "tree"';
          str.replace(/"tree"/g, '"wall"');

Replace is not happening. Please help

Brien Foss
  • 3,336
  • 3
  • 21
  • 31
Chaitanya
  • 21
  • 2
  • or see [w3schools](https://www.w3schools.com/jsref/jsref_replace.asp), mozilla [documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace), MS [documentation](https://learn.microsoft.com/en-us/scripting/javascript/reference/replace-method-string-javascript) ... – mcalex Feb 01 '18 at 03:56

1 Answers1

3

You just need to save your string after you replace it.

var str = 'The quick fox jumped over "tree"'; 
str = str.replace('"tree"', '"wall"');
console.log(str);
Josh Adams
  • 2,113
  • 2
  • 13
  • 25