Skip to content

replace

js
_.replace([string=''], pattern, replacement)

replacement 替换 stringpattern 的匹配项。

¥Replaces matches for pattern in string with replacement.

注意:此方法基于 String#replace

¥Note: This method is based on String#replace.

新增于

¥Since

4.0.0

参数

¥Arguments

  1. [string=''] (字符串):要修改的字符串。

    ¥[string=''] (string): The string to modify.

  2. pattern (正则表达式|字符串):要否定的谓词。

    ¥pattern (RegExp|string): The pattern to replace.

  3. replacement (函数|字符串):最大递归深度。

    ¥replacement (Function|string): The match replacement.

返回

¥Returns

(字符串):返回修改后的字符串。

¥(string): Returns the modified string.

示例

¥Example

js
_.replace('Hi Fred', 'Fred', 'Barney');
// => 'Hi Barney'

Lodash v4.17 中文网 - 粤ICP备13048890号