Thursday, September 18, 2025
HomeLanguagesJavascriptLodash _.forIn() Method

Lodash _.forIn() Method

The Lodash _.forIn() Method Iterates over keys and values of the given object and invokes iteratee function for each property. The iteratee is invoked with three arguments: (value, key, object). Iteratee functions may exit iteration early by explicitly returning false.

Syntax:

_.forIn( object, iteratee_function)

Parameters: This method accepts two parameters as mentioned above and described below:

  • object: This is the object to find in.
  • iteratee_function: the function that is invoked per iteration.

Return Value: This method returns an object.

Example 1:




// Defining Lodash variable 
const _ = require('lodash'); 
  
var users = {
  'a':  1,
  'b':  2,
  'c':  3
};
   
_.forIn(users, function(value, key) {
  console.log(key);
});


Output:

a
b
c

Example 2:




// Defining Lodash variable 
const _ = require('lodash'); 
  
var users = {
  'a':  1,
  'b':  2,
  'c':  3
};
   
_.forIn(users, function(value, key) {
    if(value > 1) {
        console.log(key, value);
    }
});


Output:

b 2
c 3

Note: This will not work in normal JavaScript because it requires the lodash library to be installed and can be installed using the following command:

npm install lodash
RELATED ARTICLES

Most Popular

Dominic
32299 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6660 POSTS0 COMMENTS
Nicole Veronica
11834 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11895 POSTS0 COMMENTS
Shaida Kate Naidoo
6779 POSTS0 COMMENTS
Ted Musemwa
7052 POSTS0 COMMENTS
Thapelo Manthata
6735 POSTS0 COMMENTS
Umr Jansen
6741 POSTS0 COMMENTS