Lodash - startsWith 方法



语法

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

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

参数

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

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

  • [position=0] (数字) - 开始搜索的位置。

输出

  • (布尔值) - 如果字符串以目标开头,则返回 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.htm
广告
© . All rights reserved.