Using $.each() and check object or array for each object.
- if object index is "id", push id object into result array
- if object is array or object, call recursively.
- if not, just return.
Here's some code. Working code is at http://jsfiddle.net/cwdoh/KKFCZ/
function getAll( input, target ) {
var result = [];
function parseData( input, target ) {
$.each( input, function ( index, obj ) {
if ( index == target ) {
result.push( obj );
}
else {
switch ( $.type( obj ).toLowerCase() ) {
case "object":
case "array":
parseData( obj, target );
break;
}
}
} );
}
parseData( data, "id" );
return result;
}