Lodash spilt method
语法
_.split([string=''], separator, [limit])
Splits string by separator.
参数
[string=''] (string) − The string to split.
separator (RegExp|string) − The separator pattern to split by.
[limit] (number) − The length to truncate results to.
输出
(Array) − Returns the string segments.
实例
var _ = require('lodash');
var result = _.split('a-b-c', '-');
console.log(result);
result = _.split('a-b-c', '-', 2);
console.log(result);
Save the above program in
tester.js. Run the following command to execute this program.
Command
输出
[ 'a', 'b', 'c' ]
[ 'a', 'b' ]