- 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?
5 Réponses
+ 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"] )
+ 4
Oh, I figured you'd just edit; I'm not rooting for best answer here, just helping yours :)
+ 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
+ 1
ohh yeah, sorry :b
+ 1
yeah, no problem ;D