0

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

2 Answers 2

5

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]
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for giving different ways to retrieve it. I got it now. Thanks again.
1
Ext.each(test, function(item) {
   console.log(item.id); 
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.