122
rated 0 times
[
126]
[
4]
/ answers: 1 / hits: 15297
/ 9 Years ago, wed, may 27, 2015, 12:00:00
If we create some objects, and fill an array with those objects, are the names stored within the array, or only the properties of the object?
I guess this may be trivial, but I haven't been able to find an answer.
var boxA = {color: red, width: 100};
var boxB = {color: yellow, width: 200};
var boxC = {color: blue, width: 300};
boxArray = [boxA, boxB, boxC];
for (var i = 0; i < boxArray.length; i++) {
//****
// What code do we insert here to log
// boxA
// boxB
// boxC
//****
}
Of course, it is a trivial workaround to add
boxA.box = boxA;
etc and then call
console.log(boxArray[i].box);
But is that really necessary?
More From » arrays