- newString: a new string with some or all matches of a pattern replaced by a new string we specify(notice how the original string is not modified)
- regexp: a RegExp object or literal that will be replaced by our newSubstring. Treated as verbatim and not interpreted as a regular expression.
- substring: a string to be replaced with our newSubString. Only the first occurrence will be replaced
- newSubstring: the string that will be our replacement for the expression specified earlier(regexp or substring). Some special replacement patterns are also supported in this case; see this link.
- function: we can also, instead of using newSubstring, specify a function as the second parameter of replace. When this happens, the function will be invoked after the match has been performed. The function’s returning value will be used as the replacement string.
Also notice as mentioned above, that in case you provide a string as a replacement pattern only its first occurrence will be modified
Other useful resources
- Using the filter function at this link
- Using the for of loop at this link
- Keeping up-to-date with the latest standards when it comes to typescript