Lodash - endsWith 方法
語法
_.endsWith([string=''], [target], [position=string.length])
檢查字串是否以給定目標字串結尾。
引數
[string=''] (string) − 要檢查的字串。
[目標] (字串) − 要搜尋的字串。
[位置 = 字串長度](數字) − 要搜尋到的位置。
輸出
(布林值) − 如果字串以目標結尾,則返回 true,否則返回 false。
示例
var _ = require('lodash');
var result = _.endsWith('abc', 'c');
console.log(result);
result = _.endsWith('abc', 'b', 2);
console.log(result);
將上述程式儲存在 tester.js 中。執行以下命令來執行該程式。
命令
\>node tester.js
輸出
true true
lodash_string.htm
廣告