4 ways to convert a string to an array in Javascript

? 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…


This content originally appeared on DEV Community and was authored by Maria Antonella ?

? 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 '] 

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


This content originally appeared on DEV Community and was authored by Maria Antonella ?


Print Share Comment Cite Upload Translate Updates
APA

Maria Antonella ? | Sciencx (2021-08-18T15:29:09+00:00) 4 ways to convert a string to an array in Javascript. Retrieved from https://www.scien.cx/2021/08/18/4-ways-to-convert-a-string-to-an-array-in-javascript/

MLA
" » 4 ways to convert a string to an array in Javascript." Maria Antonella ? | Sciencx - Wednesday August 18, 2021, https://www.scien.cx/2021/08/18/4-ways-to-convert-a-string-to-an-array-in-javascript/
HARVARD
Maria Antonella ? | Sciencx Wednesday August 18, 2021 » 4 ways to convert a string to an array in Javascript., viewed ,<https://www.scien.cx/2021/08/18/4-ways-to-convert-a-string-to-an-array-in-javascript/>
VANCOUVER
Maria Antonella ? | Sciencx - » 4 ways to convert a string to an array in Javascript. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/18/4-ways-to-convert-a-string-to-an-array-in-javascript/
CHICAGO
" » 4 ways to convert a string to an array in Javascript." Maria Antonella ? | Sciencx - Accessed . https://www.scien.cx/2021/08/18/4-ways-to-convert-a-string-to-an-array-in-javascript/
IEEE
" » 4 ways to convert a string to an array in Javascript." Maria Antonella ? | Sciencx [Online]. Available: https://www.scien.cx/2021/08/18/4-ways-to-convert-a-string-to-an-array-in-javascript/. [Accessed: ]
rf:citation
» 4 ways to convert a string to an array in Javascript | Maria Antonella ? | Sciencx | https://www.scien.cx/2021/08/18/4-ways-to-convert-a-string-to-an-array-in-javascript/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.