Skip to content

Instantly share code, notes, and snippets.

@amslezak
Created May 25, 2016 02:54
Show Gist options
  • Save amslezak/4ee795e1a33579243f67664ecc99e25d to your computer and use it in GitHub Desktop.
Save amslezak/4ee795e1a33579243f67664ecc99e25d to your computer and use it in GitHub Desktop.
map filter lodash 4 example
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