+ 1

javascript array

how can i assign the js array from user input ? var arr= new array(2) arr[1]= window.prompt("enter number") it doesn't work

22nd Dec 2017, 8:16 AM
Wei le Yi
Wei le Yi - avatar
3 Answers
+ 9
@Pegasus: You must use "var" NOT "int", right? :)
22nd Dec 2017, 9:07 AM
Dev
Dev - avatar
+ 3
Initialize the array with length x. Then, for (int i=0;i<x;i++){ array[i]=prompt("Enter value") }
22nd Dec 2017, 8:51 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar