0

I'm trying to replace all instances of 'formattedTime' in a massive string. Here's my code

googleTrends.interestOverTime({keyword: selectedTopic})
    .then((results) => {
    results.replace(/formattedTime/g, 'no what the heck');
    console.log(results);
})
    .catch((err) => {
    console.error('Oh no there was an error', err);
});

I am not receiving any errors however nothing is happening inside my console. I even tried replacing a single line string but none of it will work. It might be because of the promise I'm receiving? I am relatively new to RegEx so I thought maybe that was an issue but it doesn't seem to be.

1
  • The replace() method searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced; thus update or return the result. Commented Jun 17, 2018 at 19:00

1 Answer 1

0

Strig.prototype.replace does not mutate the string. Strings are immutable. It will return a new string.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.