Created
November 6, 2016 21:05
-
-
Save ScottBurfieldMills/79ee58cc3b7484344d2d3f7d4a9e2be8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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