
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Write the usage of split() method in javascript?
The split([separator, [limit]]) method splits a String object into an array of strings by separating the string into substrings, using a specified separator string to determine where to make each split.
Example usage of split method
let a = "hello,hi,bonjour,namaste"; let greetings = a.split(','); console.log(greetings)
Output
[ 'hello', 'hi', 'bonjour', 'namaste' ]
Note that the commas were removed here. Any separator provided will be removed.
If separator is an empty string, str is converted to an array having one element for each character of str.
Example
let a = "hello"; console.log(a.split(""))
Output
[ 'h', 'e', 'l', 'l', 'o' ]
If no separator is provided, the string is returned as is.
Example
let a = "hello world" console.log(a.split())
Output
hello world
- Related Articles
- Explain the usage of the split() method of the String class in Java.
- What is the usage of every() method in JavaScript?
- What is the usage of fill() method in JavaScript?
- What is the usage of copyWithin() method in JavaScript?
- What is the usage of some() method in JavaScript?
- What is the usage of join() method in JavaScript?
- What is the usage of Array.Every() method in JavaScript?
- Write the use of Array.reduceRight() method in JavaScript?
- Write the importance of shift() method in javascript array?
- Demonstrate the usage of the Pattern.split() method in Java
- Usage of HTML5 Blob.slice() method
- Usage of element() method of Queues in Java
- What is the usage of in operator in JavaScript?
- What is the usage of onhashchange event in JavaScript?
- What is the usage of onpageshow event in JavaScript?

Advertisements