Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ScottBurfieldMills/79ee58cc3b7484344d2d3f7d4a9e2be8 to your computer and use it in GitHub Desktop.
Save ScottBurfieldMills/79ee58cc3b7484344d2d3f7d4a9e2be8 to your computer and use it in GitHub Desktop.
// Fetch the name of the first pet from each owner
var ownerArr = [{
"owner": "Colin",
"pets": [{"name":"dog1"}, {"name": "dog2"}]
}, {
"owner": "John",
"pets": [{"name":"dog3"}, {"name": "dog4"}]
}];
// Array's map method.
ownerArr.map(function(owner){
return owner.pets[0].name;
});
// Lodash
_.map(ownerArr, 'pets[0].name');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment