Open In App

Lodash _.forOwnRight() Method

Last Updated : 03 Nov, 2023
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

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

Syntax:

_.forOwnRight( 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, the function is iterating the value from right to left and checking the condition if it satisfies the condition it prints the result in the console.

JavaScript
// Defining Lodash variable 
const _ = require('lodash');

let users = {
    'a': 1,
    'b': 2,
    'c': 3
};

_.forOwnRight(users, function (value, key) {
    console.log(key, '=', value);
});

Output:

c = 3
b = 2
a = 1

Example 2: In this example, the function is iterating the value from right to left and checking the condition if it satisfies the condition it prints the result in the console.

JavaScript
// Defining Lodash variable 
const _ = require('lodash');

let users = {
    'a': 1,
    'b': 2,
    'c': 3
};

_.forOwnRight(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 npm install lodash.


Similar Reads