lodash find index code example

Example 1: lodash find object in array

var users = [
  { 'user': 'barney',  'age': 36, 'active': true },
  { 'user': 'fred',    'age': 40, 'active': false },
  { 'user': 'pebbles', 'age': 1,  'active': true }
];
 
_.find(users, function(o) { return o.age < 40; });
// => object for 'barney'

Example 2: lodash _ findindex examples

var users = [  { 'user': 'barney',  'active': false },  { 'user': 'fred',    'active': false },  { 'user': 'pebbles', 'active': true }]; _.findIndex(users, function(chr) {  return chr.user == 'barney';});// => 0 // using the `_.matches` callback shorthand_.findIndex(users, { 'user': 'fred', 'active': false });// => 1 // using the `_.matchesProperty` callback shorthand_.findIndex(users, 'active', false);// => 0 // using the `_.property` callback shorthand_.findIndex(users, 'active');// => 2

Example 3: get lodash

var object = { 'a': [{ 'b': { 'c': 3 } }] }; _.get(object, 'a[0].b.c');// => 3 _.get(object, ['a', '0', 'b', 'c']);// => 3 _.get(object, 'a.b.c', 'default');// => 'default'

Tags:

Misc Example