

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- Explain the usage of the split() method of the String class in Java.
- What is the usage of join() method in JavaScript?
- 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 Array.Every() method in JavaScript?
- Write the use of unshift() 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?
- Explain the usage of the valueOf() method of the String class in Java
Advertisements