Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
replaceAll() replaces every occurrence of a substring! Unlike replace() which only replaces the first match, replaceAll() changes all matches - and you don't need regex!
str.replace(/find/g, 'replace'). Now: str.replaceAll('find', 'replace')!Simple string replacement without regex
Practical scenarios for replaceAll
| Feature | replace() | replaceAll() |
|---|---|---|
| String replacement | First only | All matches ✅ |
| Regex with /g flag | All matches | All matches |
| Requires regex | For all matches | No ✅ |
| ES Version | ES3 | ES2021 |
Replaces every occurrence, not just first
Plain strings work (but regex still supported)
Can chain multiple replaceAll() calls
Modern convenience method