How to split the string into an array in JavaScript
In this post we will give you information about How to split the string into an array in JavaScript. Hear we will give you detail about How to split the string into an array in JavaScriptAnd how to use it also give you demo for it if it is necessary.
we are going to learn about two different ways to split the string into an array in JavaScript.
First way: Using Split() method
In JavaScript, we have the built-in split() method which helps us to split the string into an array of strings.
Example:
const name = "zero";const array = name.split('');console.log(array); // ["z", "e", "r", "o"]
In the above example, we have passed empty string ” as an argument to the split() method so that it returns the array of individual strings.
Second way: Es6 spread operator
We can also use the es6 spread operator … to split the string into an array.
Example:
const name = "zero";const array = [...name];console.log(array); // ["z", "e", "r", "o"]
Hope this code and post will helped you for implement How to split the string into an array in JavaScript. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs