VOOZH about

URL: https://www.geeksforgeeks.org/javascript/lodash-_-every-method/

⇱ Lodash _.every() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Lodash _.every() Method

Last Updated : 3 Sep, 2024

Lodash _.every() method checks if the predicate returns true for all elements of the collection and iteration is stopped once the predicate returns falsely.

Note: Also this method returns true for empty collections because everything is true for elements of empty collections.

Syntax

_.every(collection, [predicate=_.identity]);

Parameters:

  • collection (Array|Object): This parameter holds the collection to iterate over.
  • [predicate=_.identity] (Function): This parameter holds the function invoked per iteration.

Return Value:

This method is used to return true if all elements pass the predicate check, else false.

Example 1: In this example, we are checking is every element of the given array has that data type or not and printing the result by the use of the _.every() method.

Output:

false
true

Example 2: In this example, we are checking is every element of the given array has that same object or not and printing the result by the use of the _.every() method.

Output:

false

Example 3: In this example, we are checking is every element of the given array of objects has that same field or not and printing the result by the use of the _.every() method.

Output:

true

Example 4: In this example, we are checking is every element of the given array of objects has that string or not and printing the result by the use of the _.every() method.

Output:

false
Comment