Created
May 25, 2016 02:54
-
-
Save amslezak/4ee795e1a33579243f67664ecc99e25d to your computer and use it in GitHub Desktop.
map filter lodash 4 example
This file contains 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
var _ = require('lodash'); | |
var users = [ | |
{id: 1, name: "Nelson", roles: ["admin"]}, | |
{id: 5, name: "Mike", roles: ["admin"]}, | |
{id: 2, name: "Andy", roles: ["registered, moderator"]}, | |
{id: 3, name: "Dan", roles: [""]}, | |
{id: 4, name: "Tim", roles: ["moderator"]}, | |
] | |
var admins = _(users) | |
.filter(u => _.includes(u.roles, "admin")) | |
.map('name') | |
.value() | |
console.log(admins) | |
var user = (id) => _.find(users, {'id': id}) | |
console.log(user(2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment