Lodash – findIndex method

  • Post author:
  • Post category:Lodash
  • Post comments:3 Comments
Lodash - fill method

Syntax Of Lodash findIndex method

_.findIndex(array, [predicate=_.identity], [fromIndex=0])

This Lodash findIndex method is like _.find except that it returns the index of the first element predicate returns truthy for instead of the element itself.

Arguments

  • array (Array) − The array to inspect.
  • [predicate=_.identity] (Function) − The function invoked per iteration.
  • [fromIndex=0] (number) − The index to search from.

Output

  • (number) − Returns the index of the found element, else -1.

Example

var _ = require('lodash');
var users = [
   { user: 'Sam', active: false },
   { user: 'Ted', active: true },
   { user: 'Julie', active: false }
];

var result = _.findIndex(users, function(user) { return !user.active; });
console.log(result);

result = _.findIndex(users, ['active', false]);
console.log(result);

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

0
0

Next Topic – Click Here

This Post Has 3 Comments

  1. ikaria juice

    Thanks for your publish. My spouse and i have continually noticed that most people are wanting to lose weight because they wish to show up slim and attractive. On the other hand, they do not always realize that there are more benefits for losing weight also. Doctors insist that fat people are afflicted by a variety of ailments that can be perfectely attributed to their excess weight. The great news is that people who are overweight and also suffering from numerous diseases are able to reduce the severity of their illnesses simply by losing weight. It is easy to see a continuous but notable improvement in health if even a small amount of fat loss is accomplished.

Leave a Reply