Can we group variable in javascript? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Can we group variable in javascript?

I have 3 variable with same value. Example : var a = 0; var b = 0; var c = 0; Is it possible to group them? If possible, how can I group them?

4th Aug 2017, 3:41 AM
Muhammad Bagus Zulmi
Muhammad Bagus Zulmi - avatar
5 Answers
+ 5
@Mane Antonio Semicolons in your object def (needs commas): var worker={ age:25, daysWorked:6, restDays:1, } Also, you can use: alert( worker["age"] )
4th Aug 2017, 4:47 AM
Kirk Schafer
Kirk Schafer - avatar
+ 4
Oh, I figured you'd just edit; I'm not rooting for best answer here, just helping yours :)
4th Aug 2017, 4:57 AM
Kirk Schafer
Kirk Schafer - avatar
+ 1
you can set them into an object like var worker={ age:25; daysWorked:6; restDays:1; } and then you access to the info like console.log(worker.age);//25 You can also set them into an array, it would look like var inches=[8,10,0]; and you access to the info by the item index console.log(inches[1])//10
4th Aug 2017, 4:03 AM
Mane Antonio
Mane Antonio - avatar
+ 1
ohh yeah, sorry :b
4th Aug 2017, 4:48 AM
Mane Antonio
Mane Antonio - avatar
+ 1
yeah, no problem ;D
4th Aug 2017, 5:50 AM
Mane Antonio
Mane Antonio - avatar