How we can do it? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How we can do it?

how we can give four numbers that are user inputs to js and js put them in an array in an order like this: var arr=[1,2,3,4 ] or var arr=[4,3,2,1] please help me

9th Jul 2018, 9:00 AM
Programmer
7 Answers
+ 7
If you want to add multiple variables into an array you can use: var arr = [a, b, c, d]; to sort or reverse them use: arr.sort() or arr.reverse()
9th Jul 2018, 9:08 AM
Michael55555
Michael55555 - avatar
+ 5
Programmer You're welcome!
9th Jul 2018, 2:07 PM
Michael55555
Michael55555 - avatar
+ 3
Here is an example code using the .sort() method: https://code.sololearn.com/WM3siEnWYqz5/?ref=app
9th Jul 2018, 10:23 AM
giannismach
giannismach - avatar
+ 1
var a=1; var b=2; var c=3; var d=4; var arr = Array.prototype.concat(a,b,c,d); console.log(arr.join(",")); arr = Array.prototype.concat(d,c,b,a); console.log(arr.join(",")); https://code.sololearn.com/W4X5Li4pf89k/?ref=app
9th Jul 2018, 9:18 AM
Calviղ
Calviղ - avatar
+ 1
no you dont get my mean i mean four varibles that are user inputs and i want java script to put them in an array in order please answer
9th Jul 2018, 9:22 AM
Programmer
0
I want to see your attempt Please show your codes.
9th Jul 2018, 9:30 AM
Calviղ
Calviղ - avatar
0
thanks all of you
9th Jul 2018, 10:41 AM
Programmer