- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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
Advertisements