lodash findIndex code example
Example 1: 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 2: 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'