2013-10-29 171 views

回答

0
objectx = {propA: 'valueA', 
    propB: 'valueB', 
    propC: [{name: 'john', id:123}, 
      {name: 'tom', id:456}] 
    } 
function getIdInPropC(objectx,id) { 
for (key in objectx.propC) { 
    var obj = objectx.propC[key]; 
    if (!obj) {continue;} 
    if (obj.id && obj.id == id) {return obj;} 
} 
    return false; 
} 
getIdInPropC(objectx, 456);//returns obj containing top and id 456 
getIdInPropC(objectx, 777);//returns false