Friday, October 24, 2025
HomeLanguagesJavascriptLodash _.split() Method

Lodash _.split() Method

The Lodash _.split() method splits the given string by the given separator and up to the given limit length.

Syntax:

_.split( string, separator, limit )

Parameters: This method accepts three parameters as mentioned above and described below:

  • string: The string to split.
  • separator: The separator by which string is to be split.
  • limit: The length to truncate results.

Return Value: This method returns an array.

Example 1:

Javascript




// Defining Lodash variable 
const _ = require('lodash'); 
  
var str = "Geeks-for-Geeks";
  
// Using _.replace() method
console.log(_.split(str, '-' ))


Output:

[ 'Geeks', 'for', 'Geeks' ]

Example 2: The array limited to size of 1.

Javascript




// Defining Lodash variable 
const _ = require('lodash'); 
  
var str = "Geeks-for-Geeks";
  
// Using _.replace() method
console.log(_.split(str, '-', 1 ))


Output:

[ 'Geeks' ]

Note: This will not work in normal JavaScript because it requires the lodash library to be installed and can be installed using npm install lodash.

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS