Thursday, October 16, 2025
HomeLanguagesJavascriptLodash _.forOwn() Method

Lodash _.forOwn() Method

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

Syntax:

_.forOwn( 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
};
   
_.forOwn(users, function(value, key) {
  console.log(key, '=', value);
});


Output:

a = 1
b = 2
c = 3

Example 2:




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


Output:

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
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS