In JS if you would like to split user entry into an array what is the best way of going about it?
For example:
entry = prompt("Enter your name")
for (i=0; i<entry.length; i++)
{
entryArray[i] = entry.charAt([i]);
}
// entryArray=['j', 'e', 'a', 'n', 's', 'y'] after loop
Perhaps I'm going about this the wrong way - would appreciate any help!
use
var array = entry.split("");
Use
split
method:Refer
String.prototype.split()
for more info.