替换未执行的promise字符串

时间:2018-06-17 18:36:24

标签: javascript regex replace promise

我试图替换' formattedTime'的所有实例。在massive string。 这是我的代码

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);
});

我没有收到任何错误,但我的控制台内没有发生任何事情。 我甚至尝试更换一个单行字符串但没有一个会起作用。这可能是因为我收到的承诺? 我对RegEx比较陌生,所以我想也许这是一个问题,但它似乎并不是。

1 个答案:

答案 0 :(得分:0)

Strig.prototype.replace不会改变字符串。字符串是不可变的。它将返回一个新字符串。