String.prototype.replaceAllbeginner'foo bar foo'.replaceAll('foo', 'baz') // β 'baz bar baz'
'banana'.replaceAll('a', 'o') // β 'bonono'Use replaceAll() to replace every occurrence of a search string or regex (with /g flag) with the replacement.
str.replaceAll(searchValue, replaceValue) replaces all occurrences of searchValue.
Challenge: Implement replaceAllOccurrences(str, from, to) that replaces every occurrence of from with to.
replaceAllOccurrences('foo bar foo', 'foo', 'baz') // β 'baz bar baz'