Lodash - replace 方法



語法

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

用 replacement 替換字串中與 pattern 匹配的內容。

引數

  • [string=''] (字串) − 要修改的字串。

  • pattern (RegExp|字串) − 要替換的模式。

  • replacement (函式|字串) − 匹配替換內容。

輸出

  • (字串) − 返回修改後的字串。

示例

var _ = require('lodash');
var result = _.replace('Hi Joe', 'Joe', 'Julie');

console.log(result);

將以上程式儲存在 tester.js 中。執行以下命令以執行此程式。

命令

\>node tester.js

輸出

Hi Julie
lodash_string.htm
廣告
© . All rights reserved.