0

How to add element in array in js from user

4th Mar 2020, 7:34 PM
arpit
arpit - avatar
6 ответов
4th Mar 2020, 7:49 PM
VEDANG
VEDANG - avatar
+ 5
You can try this code. This code will take elements separated by spaces and add them to array: var arr = [...prompt().split(' ')] console.log(arr)
4th Mar 2020, 7:39 PM
VEDANG
VEDANG - avatar
+ 3
Thanks
4th Mar 2020, 7:40 PM
arpit
arpit - avatar
+ 3
Actually I was making a program of average in js where i want user to enter any number of value in single textbox
4th Mar 2020, 7:41 PM
arpit
arpit - avatar
+ 3
arpit hi, if it have to be repeated multiple times, for exemple a teacher will calculate his student average of the year, you can store any single value entered then submited and store it in an array with the .push() method. And then apply a calcul on the array as VEDANG show.
4th Mar 2020, 11:53 PM
EmmanueLZ.
EmmanueLZ. - avatar
+ 3
Thanks for the help
5th Mar 2020, 4:56 PM
arpit
arpit - avatar