Replaces text in a string, using a regular expression or search string.
replace(searchValue, replacement)
searchValue
A string or RegExp to search for.
replacement string | function(match, …capture, offset, string, groups)
A string containing the text to replace for every successful match of searchValue in this string, or a function that returns the replacement text.
A new string.
"banana".replace(/an/g, "🍌")
"b🍌🍌a"
"banana".replace(/an/g, match => match.toUpperCase())
"bANANA"
"banana".replace("an", "AN")
"bANana"