It's logging the array, because you fed it the array. The reason why Chrome doesn't show anything inside the array is because you didn't populate it numerically. If you want to alert the name property of the first array object, then:
var albums = new Array();
var album = new Array();
album['name'] = 'This is War';
albums.push(album);
console.log(albums);
console.log(albums[0].name);
If you are just setting properties, you should use an object literal.
var albums = [], album = {};
album['name'] = 'Test';
albums.push(album)
console.log(albums);
console.log(albums[0].name);
in JS, Any object can have properties, and arrays are objects. If you have no use for numerical ordering for the album nor any of the array methods, then use an object and not an array.
meder omuraliev
- 187.3k
- 76
- 402
- 443