oneofakind
oneofakind

Reputation: 562

Javascript - EXTjs Accessing Array Values

Again, i'm quite new to Javascript and Extjs.

code:

 var test = [
        {
            id: 0,
            test: 'Hello'
        },
        {
            id: 1,
            test: 'World'
        }
    ];

how do I get the ID of each instance?.

Thanks for the reply.

Regards, Ronel

Upvotes: 0

Views: 2334

Answers (2)

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100195

do you mean:

for(var i = 0; i < test.length; i++) {
  console.log( test[i].id);
}

or

console.log( test[0].id); //for first
console.log( test[1].id); //for second

in Extjs, you can use iterator function:

Ext.each(test, function(val, index) {
  console.log(val.id)
});

OR

Ext.pluck(test, 'id'); //returns [0, 1]

Upvotes: 5

chinabuffet
chinabuffet

Reputation: 5598

Ext.each(test, function(item) {
   console.log(item.id); 
});

Upvotes: 1

Related Questions