4 ways to convert a string to an array in Javascript

Maria Antonella 🦋 - Aug 18 '21 - - Dev Community

🐞 Today I share with you four ways to convert a string to an array in JavaScript.

const str = 'antonella';

str.split('');

let newStr = [...str];

Array.from(str);

Object.assign([],str);

// ['a ', 'n ', ' t ', 'o ', ' n ', ' e ', ' l', ' l ', ' a '] 

Enter fullscreen mode Exit fullscreen mode

👾 So simple! But they are those things that I google every day because I never remember.😅

. . . . . . . . . . . . . . . . . .
Terabox Video Player