Skip to content

Instantly share code, notes, and snippets.

@ldmarz
Created August 10, 2018 13:43
Show Gist options
  • Save ldmarz/a9e49cf862471947fe9c2ef15934efc5 to your computer and use it in GitHub Desktop.
Save ldmarz/a9e49cf862471947fe9c2ef15934efc5 to your computer and use it in GitHub Desktop.
Example of use find function from lodash
var users = [
{ firstName: "Ldmarz", lastName: "martinez", age: 28, gender: "male" },
{ firstName: "Suli", lastName: "bern", age: 5, gender: "female" },
{ firstName: "Marianis", lastName: "Carrey", age: 54, gender: "male" },
{ firstName: "Jhon", lastName: "carret", age: 40, gender: "female" }
];
var user = _.find(users, { name: "ldmarz", gender: "male" });
// { firstName: "Ldmarz", lastName: "martinez", age: 28, gender: "male" },
var childUser = _.find(users, function(user) {
return user.age < 18;
});
// { firstName: "Suli", lastName: "bern", age: 5, gender: "female" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment