Thread: String to array
View Single Post
  #6 (permalink)  
Old January 20th, 2007, 04:02 PM
myang12 myang12 is offline
Registered User
Join Date: Jan 2007
Location: Cape Town, Western Cape, South Africa.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

It's pretty easy to do. And there is a perhaps an easier way.

/* string.split method will split a string into an array based
on the input of the parameter, for e.g. h,e,l,l,o can be put into
an array via: var arr = str.split(","); */

var str = "hello";
/* this will split each individual character into an array */
var arr = str.split("");

/* to output an array into a string, you can use string.join() */
alert(arr.join()); // outputs "hello"
alert(arr.join("-")); // outputs "h-e-l-l-o"