Lodash - endsWith 方法
语法
_.endsWith([string=''], [target], [position=string.length])
检查字符串是否以给定的目标字符串结尾。
参数
[string=''] (string) − 要检查的字符串。
[target] (string) − 要搜索的字符串。
[position=string.length] (number) −搜索到的位置。
输出
(boolean) − 如果字符串以目标结尾,则返回 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