0

I've following object

Object {  
   14533:Object,
   14598:Object,
   43281:Object,
   275047:Object,
   553883:Object,
   602381:Object,
   602639:Object,
   848489:Object,
   16891417:Object,
   26457880:Object
}

where

14533 {  
   pageid:14533,
   ns:0,
   title:"India",
   index:1,
   extract:"India, officially the Republic of I…"
}

I want to iterate through each of these 10 objects and extract pageid, title, extract

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
  • Above questions iterate through properties of object - I want to iterate through properties of object. How can I use in this context? for (var property in object) { if (object.hasOwnProperty(property)) { // do stuff } } – Pravin.Mache Jul 05 '17 at 04:43
  • Then iterate through both? – Andrew Li Jul 05 '17 at 04:44

1 Answers1

-3

This question is a replica of Iterate through object properties

Do some searching before asking questions or you will be down voted.

UPDATE:

As you will find in the link the key ingredient to solve your question is:

for(var key in obj){
    if (obj.hasOwnProperty(key)) {
        // your code
    }
}

The full solution would look something like this:

for(var key in obj){
    if (obj.hasOwnProperty(key)) {
        var thisObj = obj[key];
        var thisPageId = thisObj.pageid;
        var thisTitle = thisObj.title;
        var thisExtract = thisObj.extract;

        // console test
        console.log(key, thisPageId, thisTitle, thisExtract);
    }
} 
Zuks
  • 1,247
  • 13
  • 20
  • If you think this is a duplicate please flag it and not add as answer.. This will be a _link only answer_ and would end up downvoted and/or deleted – Suraj Rao Jul 05 '17 at 04:34
  • Both of the above questions are about iterating through object properties and not properties of abject inside object – Pravin.Mache Jul 05 '17 at 04:51
  • @Pravin.Mache I have updated the answer... You said "I want to iterate through each of these 10 objects and extract pageid, title, extract"... The (key in obj) for loop precisely fulfils the first part of your question and the rest is rather straightforward. – Zuks Jul 05 '17 at 05:24