String Split() Method
The String Split() Method takes the pattern as an argument and returns the target string as a list or array. The separator represents the function where to split and the limit represents the number of substrings or lengths up to which the string will be processed.
Syntax:
split(separator); // or
split(separator, limit);
Example:
// Declare a String
let str= "w3wiki";
// Use String split() method to
// Convert String to an Array
let arr = str.split('');
console.log(arr);
Output
[ 'G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's' ]
String to Array in JavaScript
In this article, you will learn how to convert a string to an array data type in JavaScript.
There are various methods to convert a String to an Array that is described below:
Table of Content
- Spread Operator
- Naive Method
- String Split() Method
- Array from() method
- Using slice() Method
- Using Array.prototype.map()