JavaScript String split()2 Apr 2025 | 3 min read As the name implies, the split() method in JavaScript splits the string into the array of substrings, puts these substrings into an array, and returns the new array. It does not change the original string. When the string is empty, rather than returning an empty array, the split() method returns the array with an empty string. The empty array is returned when both string and separator are empty strings. SyntaxThe function arguments are discussed as follows. separator: It is an optional parameter. It can be a regular expression or a simple string. It specifies the point where the split should take place. If it has multiple characters, then the sequence of the entire character must be found to split. If the separator is not present in the given string, or if it is omitted, then the entire string becomes a single array element. In these cases, the returned array contains a single element consisting of the entire string. If the separator is present at the beginning or the end of the string, then it still has the effect of splitting. The returned array consists of an empty string of zero length that appears at the beginning or the last position of the returned array. limit: It is also an optional parameter. It is a non-negative integer that specifies the number of limits. It defines the higher limit on the number of splits to be found in the given string. If it is given, it splits the string at each occurrence of the specified separator. It stops when the limit entries have been placed in the array. An array can contain fewer entries than the given limit. It happens when the end of the string is reached before the limit is reached. Let's understand the split() method using some examples. Example1In this example, the split() function splits the string str wherever the whitespace (" ") occurs and returns an array of strings. Here, we are using the limit argument and providing the value of the limit argument to 3. Output Welcome,to,the Example2In this example, we are using the letter 't' as the separator of the given string. The split() function will make an array of strings by splitting the given string at each occurrence of the letter 't'. Here, we are not specifying the limit argument. Output Welcome ,o ,he TpointTec,.com Example3In this example, we are omitting the separator parameter. In the output, we can see that the returned array contains a single element consists of the given string. Output Welcome to the TpointTech.com Example4Here, we are defining the limit parameter and using the letter 'o' as the separator of the given string. The split() function will create an array of strings by splitting the given string wherever the given letter 'o' occurs until the limit is reached. The limit parameter limits the number of splits to 2 because we are defining 2 as the value of the limit. In the output, we can see that the splitting only happens twice. Output Welc,me t Next TopicParse-meaning-in-javascript |
How Do Browsers Operate with JavaScript? The JavaScript engine inside the browser runs JavaScript code. The JavaScript engine used by Firefox is known as SpiderMonkey, and it is specific to every browser. The browser downloads the HTML, CSS, and JavaScript documents whilst you go to a web...
6 min read
Programming languages such as JavaScript are adaptable and give various methods to working with this keyword and function arguments. The call() and apply() methods are two of the most often used techniques for these kinds of applications. You can call a function with arguments and specify...
6 min read
The JavaScript Regex compile method helps to return the function's output after compiling regex. It helps to get messages after working on the javascript regex pattern. Syntax The following syntax is used to get the compile time error or message. regexObject.compile("Regexp", "modifier"); Supported Browsers The browsers supported by the Regex...
4 min read
In JavaScript, a timer is created to execute a task or any function at a particular time. Basically, the timer is used to delay the execution of the program or to execute the JavaScript code in a regular time interval. With the help of timer,...
5 min read
We will discuss the in this article. Browser extension A browser extension is used to add the properties of a particular software on the web browser. Web browsers permit you to install different kinds of software extensions and permit you to extend the properties of the browser. In...
3 min read
JavaScript is one of the most generally utilized programming languages. It offers different operators for arithmetic operations, including subtraction. Understanding how the minus operator functions in JavaScript is essential for developers to control numerical values. In this article, we will explore the subtleties of the minus...
6 min read
JavaScript has made some amazing progress since its beginning during the 1990s. From its unassuming starting points as a basic scripting language for adding intuitiveness to web pages, JavaScript has developed into a strong and flexible language that drives current web development. With the ascent...
12 min read
In JavaScript, a JavaScript engineer is a person who will use JavaScript for creating applications in software. JavaScript engineer is also known as JavaScript engineer. There are some responsibilities to JavaScript engineers including the development of code libraries and optimizing applications for durability and scalability. If...
4 min read
This article gives an overview of the return statement in JavaScript. The return statement is placed after the execution of a function and is used to stop any further processing within that function while returning a specified value. In JavaScript, it is necessary for a...
4 min read
The strings are usually used to store and manipulate the text data. However, you can also store special characters and numeric data in strings as well. E.g., address or email id, which contains multitype data. Strings are created by putting data inside the quotes. JavaScript and...
3 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India