I am trying to create a Array of Array containing objects,
Here is my code,
var objA = new Array();
function myFunction(){
objA ['1'] = new Array();
objA ['1'].push({'bird':'parrot','animal':'rabbit'});
var item = objA ['1'];
alert(item['bird']);
}
Now ideally above code should alert ‘parrot’, but instead I get ‘undefined’.
What am I doing wrong?
You set the attribute to a new array:
So, of course, when you retrieve it, you’re getting back an array.
Arrays don’t have a
birdattribute. The first item in the array does, though.