Lodash - startsWith 方法

语法

_.startsWith([string=''], [target], [position=0])

检查字符串是否以给定的目标字符串开头。

参数

  • [string=''] (string) − 要检查的字符串。

  • [target] (string) − 要搜索的字符串。

  • [position=0] (number) − 要从中搜索的位置。

输出

  • (boolean) −如果字符串以目标开头,则返回 true,否则返回 false。

示例

var _ = require('lodash');
var result = _.startsWith('abc', 'b');

console.log(result);

result = _.startsWith('abc', 'b', 1);
console.log(result);

将上述程序保存在tester.js中。运行以下命令执行该程序。

命令

\>node tester.js

输出

false
true

lodash_string.html