Tuesday, July 24, 2012

Find an object and its properties within a larger object with javascript/jquery




family = {
\'person1\':[{\"id\":\"1111\",\"name\":\"adam\", \"sex\":\"male\", \"born\":\"USA\"}],
\'person2\':[{\"id\":\"2222\",\"name\":\"sarah\", \"sex\":\"female\", \"born\":\"Canada\"}],
\'person3\':[{\"id\":\"3333\",\"name\":\"adam\", \"sex\":\"male\", \"born\":\"USA\"}]
};


Given the family object above, how do I extract all the properties (id, name, sex, born) of one of the person objects that have a specific id (or name) value? eg id=1111


So ideally I can get a new object personInQuestion that I can manipulate, where:



personInQuestion = {\"id\":\"1111\",\"name\":\"adam\", \"sex\":\"male\", \"born\":\"USA\"}






Rating: 4 out of 5 based on 3 ratings



The post Find an object and its properties within a larger object with javascript/jquery appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/find-an-object-and-its-properties-within-a-larger-object-with-javascriptjquery.html

No comments:

Post a Comment