A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/lodash-_-split-method/ below:

Lodash _.split() Method - GeeksforGeeks

Lodash _.split() Method

Last Updated : 25 Oct, 2023

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

Syntax:
_.split(string, separator, limit);
Parameters: Return Value:

This method returns an array.

Example 1: In this example, we are splitting the given array by '-' by the use of the _.split() method.

JavaScript
// Defining Lodash variable 
const _ = require('lodash');

let str = "Geeks-for-Geeks";

// Using _.replace() method
console.log(_.split(str, '-'))

Output:

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

Example 2: In this example, we are splitting the given array by '-' with limit of 2 by the use of the _.split() method.

JavaScript
// Defining Lodash variable 
const _ = require('lodash');

let 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.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4