.replaceAll()
Anonymous contributor
Anonymous contributor1 total contribution
Anonymous contributor
Published Oct 9, 2023
Contribute to Docs
The .replaceAll()
method returns a new string by replacing all the matches in a string of a given search value with a given replacement value.
Syntax
string.replaceAll(searchValue, replacementValue);
The searchValue
can be either a string or RegExp.
Example
Replace all the occurrences of "scream"
with "laugh"
:
const sentence = `I scream, you scream, we all scream for ice cream.`;console.log(sentence.replaceAll('scream', 'laugh'));
This example results in the following output:
I laugh, you laugh, we all laugh for ice cream.
All contributors
- Anonymous contributorAnonymous contributor1 total contribution
- Anonymous contributor
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.