+ 1

Convert string to array?

In JavaScript, how do I convert a string to an array? For example, var a = “hello” ; var b = a ... #however you convert to array #b[1] = “e” How do I gets this result? I’m trying to output a string one letter at a time to make it look like I’m typing. Thanks for any answers.

15th Apr 2018, 3:56 AM
Pete Cowling
Pete Cowling - avatar
8 ответов
+ 12
to convert a string to an array use split(): var string="hello"; string=string.split(""); console.log(string); //h,e,l,l,o
15th Apr 2018, 4:09 AM
᠌᠌Code X
᠌᠌Code X - avatar
+ 8
Xan first of all,i clearly recall we both answered at the same time,also im highly disappointed youre more concerned about attention than the fact that youve shared your knowledge.Thanks for the downvote anyway,your maturity is as clear as crystal
15th Apr 2018, 9:33 AM
᠌᠌Code X
᠌᠌Code X - avatar
+ 8
🇳🇬Brains Your example code wouldn't work. You'd need to assign the return array to another variable to access the array. See the 2nd line on Xan 's code. The output as it stands would simply be "hello" instead of ["h", "e", "l", "l", "o" ].
15th Apr 2018, 9:39 AM
David Carroll
David Carroll - avatar
+ 5
xan firstly im not downvoting you,i hate doing that,and itsnt my fault this happened
15th Apr 2018, 10:15 AM
᠌᠌Code X
᠌᠌Code X - avatar
+ 5
see i have better things to do in real life,im less concerned about downvoting people or giving a thing of who likes my comments or not.Well..nice day xan
15th Apr 2018, 10:20 AM
᠌᠌Code X
᠌᠌Code X - avatar
+ 4
🇳🇬Brains Anyway, huge compassion to you. I've had a brutal week. Apologies for being out of line with you. I've followed you ☺ You're a good person.
15th Apr 2018, 10:20 AM
Emma
+ 1
Thanks for all the answers... and the maturity 😂. I’ll try to use this, thank you
15th Apr 2018, 4:00 PM
Pete Cowling
Pete Cowling - avatar
+ 1
This var a = "hello" ; var b = a.split("") ; console.log(b[1]) ; works. Thanks for the name of the method!
15th Apr 2018, 6:11 PM
Pete Cowling
Pete Cowling - avatar