Lodash - escape 方法



語法

_.escape([string=''])

將 string 中的字元 "&", "<", ">", """, and "'" 轉換為對應的 HTML 實體。

引數

  • [string=''] (字串) − 要轉義的字串。

輸出

  • (字串) − 返回轉義後的字串。

示例

var _ = require('lodash');
var result = _.escape('Joe, Robert, & Julie');
console.log(result);

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

命令

\>node tester.js

輸出

Joe, Robert, & Julie
lodash_string.htm
廣告
© . All rights reserved.