The Wayback Machine - https://web.archive.org/web/20240119133018/https://www.geeksforgeeks.org/lodash-_-foreachright-method/
Open In App
Related Articles

Lodash _.forEachRight() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Lodash _.forEachRight() method iterates over elements of collection from right to left. It is almost the same as the _.forEach() method.

Syntax:

_.forEachRight( collection, iteratee );

Parameters:

  • collection: This parameter holds the collection to iterate over.
  • iteratee: It is the function that is invoked per iteration.

Return Value:

This method returns the collection.

Example 1: In this example, we are iterating the given array from right to left and printing the value in the console.

Javascript




// Requiring the lodash library 
const _ = require("lodash");
 
// Use of _.forEachRight() method
_.forEachRight(['c', 'cpp', 'java',
    'python'], function (value) {
        console.log(value);
    });


Output:

python
java
cpp
c

Example 2: In this example, we are iterating the given object from right to left and printing the value in the console.

Javascript




// Requiring the lodash library 
const _ = require("lodash");
 
// Use of _.forEachRight() method
_.forEachRight({ 'x': 1, 'y': 2 },
    function (value, key) {
        console.log(key);
    });


Output:

y
x

Note: This will not work in normal JavaScript as it requires the lodash library to be installed. 
Reference: https://lodash.com/docs/4.17.15#forEachRight

Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 03 Nov, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials