Skip to content

Instantly share code, notes, and snippets.

@smpnjn
Created December 5, 2020 15:56
Show Gist options
  • Save smpnjn/4d8308ff82ec273293352a9480fa47cd to your computer and use it in GitHub Desktop.
Save smpnjn/4d8308ff82ec273293352a9480fa47cd to your computer and use it in GitHub Desktop.
let string = 'orange apple apple apple pen';
// You need regex to replace all instances of something with replace()
let newString1 = string.replace('apple', 'kiwi'); // returns 'orange kiwi apple apple pen'
// But this is not the case with replaceAll
let newString2 = string.replaceAll('apple', 'kiwi'); // returns 'orange kiwi kiwi kiwi pen'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment