Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

deleted 122 characters in body
Source Link
meder omuraliev
  • 187.3k
  • 76
  • 402
  • 443

It's logging the array, because you fed but it the array. The reason why Chrome doesn't show anything inside the array isseems empty, because you didn't populate it numerically ( which is how arrays should be populated ). If you want to alertYou can still access 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 settingin JS, Any object can have properties, and arrays are objects. If you shouldhave no use for numerical ordering for the album nor any of the array methods, then use an object literal.and not an array:

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.

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.

It's logging the array but it seems empty, because you didn't populate it numerically ( which is how arrays should be populated ). You can still access the name property of the array,

var albums = new Array();
var album = new Array();
album['name'] = 'This is War';
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:

var albums = [], album = {};
album['name'] = 'Test';
albums.push(album)
console.log(albums); 
console.log(albums[0].name);​
Source Link
meder omuraliev
  • 187.3k
  • 76
  • 402
  • 443

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.

lang-js

AltStyle によって変換されたページ (->オリジナル) /