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.

A. Foster
  • 3
  • 3
  • 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. – wp78de Jun 17 '18 at 19:00

1 Answers1

0

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

Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151