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.
If the search value is not found, replaceAll returns the original string unchanged.
Challenge: Implement tryReplaceAll(str, from, to) using replaceAll.
tryReplaceAll('hello', 'xyz', '!!!') // β 'hello'