String To Array In One Line : JavaScript

shivamkapasia0

shivamkapasia0

Posted on October 31, 2021

String To Array In One Line : JavaScript

Hey folks!
we can easily convert String into an array by using spread operator (...) :

const string = 'Shivam Kapasia';
const array = [...string];
console.log(`${array}`); // S,h,i,v,a,m, ,K,a,p,a,s,i,a
Enter fullscreen mode Exit fullscreen mode

Note : The array will also include space, but if you don't want to store space in array first remove space from string then use spread operator.

What’s your preferred way to convert string into an array ?

💖 💪 🙅 🚩
shivamkapasia0
shivamkapasia0

Posted on October 31, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related