so for each object in the array, you want to pluck the latlong
from the first key which also references another array of objects. Man I would fix this data structure but if you can't control it, you can do this:
#!/usr/bin/env node var data = [{ "circlemarker": [{ "type": "circle_marker" }, { "latlong": "abc" }] }, { "connector_marker": [{ "type": "icon_marker" }, { "latlong": "pqr" }] }, { "icon_marker": [{ "type": "connector_marker" }, { "latlong": "xyz" }] }]; var _ = require('lodash') , coords = []; _.each(data, function(item){ //console.log(item); var key = _(Object.keys(item)).first() , first = item[key] , latLong = _.pluck(first, 'latlong')[1]; if ( latLong ) { coords.push(latLong); } }); console.log(coords);
Produces the following output:
[ 'abc', 'pqr', 'xyz' ]