- 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

# In how many ways can we split a string in JavaScript?

In javascript, we can **split **a string in 3 ways. One is an old way in which **string.split()** method is used and later on, ES6 has provided 2 more ways to split a string. In the first way **spread operator **is used and in the second way
**array.from()** method is used. Let's discuss them in detail.

**String.split()**

### syntax

string.split();

### Example

In the following example, **string.split() **method is used to split the provided string to each individual character.

<html> <body> <script> const str = 'Tutorialspoint' var d = str.split('') document.write(d); </script> </body> </html>

### Output

T,u,t,o,r,i,a,l,s,p,o,i,n,t

**Spread operator**

### syntax

[...string];

### Example

In the following example,** ES6 Spread operator** is used to **split **the provided string into each and individual character. Its usage is very simple when comparing to** string.split() **method.

<html> <body> <script> const str = 'Tutorix' var d = [...str] document.write(d); </script> </body> </html>

### Output

T,u,t,o,r,i,x

**Array.from()**

### syntax

Array.from(str);

### Example

In the following example, **ES6 Array.from() **is used to **split **the provided string into each and individual character. It works the same as **string.repeat()** method.

<html> <body> <script> const str = 'Tutorix and Tutorialspoint' var d = Array.from(str); document.write(d); </script> </body> </html>

### Output

T,u,t,o,r,i,x, ,a,n,d, ,T,u,t,o,r,i,a,l,s,p,o,i,n,t

- Related Questions & Answers
- In how many ways can we find a substring inside a string in javascript?
- In how many ways we can convert a String to a character array using Java?
- In how many ways we can concatenate Strings in Java?
- How many ways a String object can be created in java?
- How many ways can we read data from the keyboard in Java?
- Program to find how many ways we can climb stairs in Python
- How many ways can a property of a JavaScript object be accessed?
- What are JSP declarations? In how many ways we can write JSP declarations?
- Program to find number of ways we can split a palindrome in python
- How many times can we sum number digits in JavaScript
- How can we split a string by sentence as a delimiter in Java?
- Program to check how many ways we can choose empty cells of a matrix in python
- C++ program to count in how many ways we can paint blocks with two conditions
- Program to count how many ways we can divide the tree into two trees in Python
- Program to count how many ways we can cut the matrix into k pieces in python

Advertisements