蜜豆视频

replaceAll replaceAll

Replaces all occurrences matching the target string by the replacement string in the base string.

The replacement proceeds from the beginning of the string to the end, for example, replacing 鈥渁a鈥 with 鈥渂鈥 in the string 鈥渁aa鈥 will result in 鈥渂a鈥 rather than 鈥渁b鈥.

Category

String

Function syntax

replaceAll(<parameters>)

Parameters

Parameter
Type
base
string
target
string (RegExp)
replacement
string

Signature and returned type

replaceAll(<baseString>,<sourceString>,<replacementString>)

Returns a string.

Example example

replaceAll("Hello World", "l", "x")

Returns 鈥淗exxo Worxd鈥.

Because the target parameter is a RegExp, depending on the string you want to replace, you may need to escape some characters. Refer to the example in this page.

recommendation-more-help
4f4a00c1-77c9-4eee-84df-bbe6206c3ab9