+ 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.
8 Answers
+ 12
to convert a string to an array use split():
var string="hello";
string=string.split("");
console.log(string);
//h,e,l,l,o
+ 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
+ 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" ].
+ 5
xan firstly im not downvoting you,i hate doing that,and itsnt my fault this happened
+ 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
+ 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.
+ 1
Thanks for all the answers... and the maturity đ. Iâll try to use this, thank you
+ 1
This
var a = "hello" ;
var b = a.split("") ;
console.log(b[1]) ;
works. Thanks for the name of the method!