Lodash _.forInRight() Method
Last Updated :
03 Nov, 2023
Lodash _.forInRight() method is like the _.forIn() method except that it iterates over properties of the object in the opposite order using iteratee function.
Syntax:
_.forInRight( object, iteratee_function);
Parameters:
- 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: In this example, we are iterating the given object from right to left and invoking the function then printing the result in the console.
javascript
const _ = require( 'lodash' );
let users = {
'a' : 1,
'b' : 2,
'c' : 3
};
_.forInRight(users, function (value, key) {
console.log(key);
});
|
Output:
c
b
a
Example 2: In this example, we are iterating the given object from right to left and invoking the function then printing the result in the console.
javascript
const _ = require( 'lodash' );
let users = {
'a' : 1,
'b' : 2,
'c' : 3
};
_.forInRight(users, function (value, key) {
if (value > 1) {
console.log(key, value);
}
});
|
Output:
c 3
b 2
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...