Lodash - spilt method


Advertisements

Syntax

_.split([string=''], separator, [limit])

Splits string by separator.

Arguments

  • [string=''] (string) − The string to split.

  • separator (RegExp|string) − The separator pattern to split by.

  • [limit] (number) − The length to truncate results to.

Output

  • (Array) − Returns the string segments.

Example

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

\>node tester.js

Output

[ 'a', 'b', 'c' ]
[ 'a', 'b' ]
lodash_string.htm
Advertisements