JavaScript String split() Method

Last Updated : 16 Jan, 2026

The JavaScript split() method is used to break a string into an array of substrings based on a given separator. It helps in processing and manipulating string data more easily.

  • The separator can be a character, string, or regular expression.
  • It returns an array and does not change the original string.
  • An optional limit parameter can be used to control the number of splits.
JavaScript
let str = "Hello and Welcome to GeeksforGeeks";
let words = str.split(" ");
console.log(words);

Syntax

str.split( separator, limit );

Parameters

  • separator: It is used to specify the character, or the regular expression, to use for splitting the string. If the separator is unspecified then the entire string becomes one single array element. The same also happens when the separator is not present in the string. If the separator is an empty string ("") then every character of the string is separated.
  • limit: Defines the upper limit on the number of splits to be found in the given string. If the string remains unchecked after the limit is reached then it is not reported in the array.

Return Value

This function returns an array of strings that is formed after splitting the given string at each point where the separator occurs. 

[Example 1]: The split() function divides the string "Geeks for Geeks" at "for", creating an array with two parts: ['Geeks ', ' Geeks']. It separates based on the given delimiter.

JavaScript
// JavaScript Program to illustrate split() method 
let str = 'Geeks for Geeks'
let array = str.split("for");
console.log(array); 

[Example 2]: The function split() creates an array of strings by splitting str wherever " " occurs.

JavaScript
// JavaScript Program to illustrate split() function
let str = 'It is a 5r&e@@t Day.'
let array = str.split(" ");
console.log(array);
Comment

Explore