A RetroSearch Logo

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

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript-string-prototype-split-function/ below:

JavaScript String split() Method - GeeksforGeeks

JavaScript String split() Method

Last Updated : 10 Jan, 2025

The JavaScript split() method divides a string into an array of substrings based on a specified separator, such as a character, string, or regular expression. It returns the array of split substrings, allowing manipulation of the original string data in various ways.

JavaScript
let str = "Hello and Welcome to GeeksforGeeks";
let words = str.split(" ");
console.log(words);
Syntax
str.split( separator, limit );
Parameters 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: 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); 

Output
[ 'Geeks ', ' Geeks' ]

Example: 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);

Output
[ 'It', 'is', 'a', '5r&e@@t', 'Day.' ]

We have a complete list of Javascript string methods, to check those please go through this Javascript String Complete reference article.

Supported Browsers

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