When I type a number with prompt var myNumber = parseInt(prompt("..."))I want it to be converted into an array of numbers. When I try with myNumber = myNumber.split("") it returns:
Object 1 has no method 'split'
help me please
When I type a number with prompt var myNumber = parseInt(prompt("..."))I want it to be converted into an array of numbers. When I try with myNumber = myNumber.split("") it returns:
Object 1 has no method 'split'
help me please
You cannot split the int, you need to have a string data type for this code to work!
So, I would like to suggest to first split it and then convert it to int as
var numbers = "1, 2, 3";
var eachNumber = numbers.split(",");
/* now parse them or whatso ever */
This will work, as you're just splitting the string. And then you will parse it just the way you did it in the first method (of yours).
var intArray = prompt("...").split(" ").map(Number);
map by simply writing .map(Number), try it outYou would need to change the number to string, then split it.
You would then want to return it to an integer.
var myNumber = parseInt(prompt("Enter your number"));
var tempString = myNumber + "";
var arr = tempString.split("");
console.log(arr);
Here is a fiddle - http://jsfiddle.net/kellyjandrews/Wa5zD/