Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Lodash-Array
  • Lodash-Collection
  • Lodash-Function
  • Lodash-Lang
  • Lodash-Math
  • Lodash-Object
  • Lodash-Sequence
  • Lodash-String
  • Lodash-Util
  • JavaScript
  • Web Technology
Open In App

Lodash _.split() Method

Last Updated : 25 Oct, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

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

Syntax:

_.split(string, separator, limit);

Parameters:

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

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.


T

taran910
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • JavaScript-Lodash

Similar Reads

    Lodash _.camelCase() Method
    Lodash _.camelCase() method is used to convert a string into a camel case string. The string can be space-separated, dash-separated, or can be separated by underscores. Syntax:_.camelCase(string);Parameters:string: This parameter holds the string that needs to be converted into a camel case string.R
    1 min read
    Lodash _.capitalize() Method
    The _.capitalize() method is a part of the Lodash library and is used to format strings. It takes a string as input and returns a new string where the first character is uppercase and all other characters are lowercase. This method is commonly used when formatting user inputs or ensuring consistent
    4 min read
    Lodash _.deburr() Method
    Lodash _.deburr() method is used to convert Latin-1 Supplement and Latin Extended-A letters to basic Latin letters and removing combining diacritical marks. Syntax:_.deburr([string='']);Parameters: string: This parameter holds the Latin-1 Supplement and Latin Extended-A letters string.Return Value:
    1 min read
    Lodash _.endsWith() Method
    Lodash _.endsWith() method is used to check whether the string ends with the given target string or not. Syntax:_.endsWith([string=''], [target], [position=string.length]);Parameters: string: This parameter holds the string that needs to be inspected.target: This parameter holds the string that need
    1 min read
    Lodash _.escape() Method
    Lodash _.escape() method is used to convert the characters "&", "<", ">", '"', and "'" of the given string into their corresponding HTML entities. Syntax:_.escape([string='']);Parameter:string: This parameter holds the string containing escape characters.Return Value: This method returns t
    1 min read
    Lodash _.escapeRegExp() Method
    Lodash _.escapeRegExp() method is used to escape the Regular Expression special characters "^", "$", "", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", and "|" in string. Syntax:_.escapeRegExp([string='']);Parameters:string: This parameter holds the string to escape.Return Value:This method retur
    1 min read
    Lodash _.kebabCase() Method
    Lodash _.kebabCase() method is used to convert the given string into a kebab case string. kebabCase is the practice of writing identifiers using hyphens instead of spaces. The string can be space-separated, dash-separated, or can be separated by underscores. Syntax:_.kebabCase([string='']);Parameter
    1 min read
    Lodash _.lowerCase() Method
    Lodash _.lowerCase() method is used to convert the given string to lowercase. The string can be space-separated, dash-separated, or can be separated by underscores. Syntax:_.lowerCase([string='']);Parameters:string: This parameter holds the string that needs to be converted into lowercase.Return Val
    1 min read
    Lodash _.lowerFirst() Method
    Lodash _.lowerFirst() method is used to convert the first character of the given string into lowercase characters. Syntax:_.lowerFirst([string='']);Parameters: string: This parameter holds the string that needs to be converted.Return Value: This method returns the converted string. Example 1: In thi
    1 min read
    Lodash _.pad() Method
    Lodash_.pad() method is used to pad the string on left and right sides if it is shorter than the given length. If the length can't be divided evenly then padding characters are truncated. Syntax:_.pad([string=''], [length=0], [chars=' '])Parameters: This method accepts three parameters as mentioned
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences