Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
116
rated 0 times [  119] [ 3]  / answers: 1 / hits: 21071  / 11 Years ago, sun, december 22, 2013, 12:00:00

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


More From » arrays

 Answers
8

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).


[#73600] Friday, December 20, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jonmicahm

Total Points: 603
Total Questions: 120
Total Answers: 108

Location: Guam
Member since Fri, Jul 31, 2020
4 Years ago
;