How to use the forInRight function from lodash

Find comprehensive JavaScript lodash.forInRight code examples handpicked from public code repositorys.

lodash.forInRight is a lodash function that iterates over object properties in reverse order and invokes a callback function for each property.

2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
* Shape.prototype.move = function(x, y) {
*   this.x += x;
*   this.y += y;
* };
*
* _.forInRight(new Shape, function(value, key) {
*   console.log(key);
* });
* // => logs 'move', 'y', and 'x' assuming `_.forIn ` logs 'x', 'y', and 'move'
*/
fork icon73
star icon711
watch icon29

137
138
139
140
141
142
143
144
145
146
module.exports.flowRight           = _.flowRight;
module.exports.fnull               = _.fnull;
module.exports.forEach             = _.forEach;
module.exports.forEachRight        = _.forEachRight;
module.exports.forIn               = _.forIn;
module.exports.forInRight          = _.forInRight;
module.exports.forOwn              = _.forOwn;
module.exports.forOwnRight         = _.forOwnRight;
module.exports.frequencies         = _.frequencies;
module.exports.fromPairs           = _.fromPairs;
fork icon19
star icon122
watch icon0

+ 92 other calls in file

How does lodash.forInRight work?

lodash.forInRight is a utility function provided by the Lodash library that iterates over the properties of an object in reverse order, calling a provided callback function for each property. The function takes two arguments: the object to iterate over and the callback function to execute for each property. The callback function is called with three arguments: the value of the current property, the key of the current property, and the object being iterated over. lodash.forInRight starts at the last property of the object and iterates backwards to the first property. This can be useful in certain situations where the order of iteration matters, such as when you need to process properties in reverse order. One thing to note is that the iteration order of an object's properties in JavaScript is not guaranteed, and may vary between different implementations or versions of JavaScript. However, lodash.forInRight provides a reliable and consistent way to iterate over an object's properties in reverse order.

638
639
640
641
642
643
644
645
646
647
648
649
650
console.log(findLastKey); // => 'b'


const forIn = _.forIn({ 'a': 1, 'b': 2 }, (value, key) => console.log(key));
// => Logs 'a' then 'b'.


const forInRight = _.forInRight({ 'a': 1, 'b': 2 }, (value, key) => console.log(key));
// => Logs 'b' then 'a'.


const forOwn = _.forOwn({ 'a': 1, 'b': 2 }, (value, key) => console.log(key));
// => Logs 'a' then 'b'.
fork icon0
star icon4
watch icon0

+ 15 other calls in file

516
517
518
519
520
521
522
523
524
525
// foo.prototype.f = 20;
// lodash.forIn(new foo(), (value, key) => {
//   console.log(value);
// });
// console.log("print from last in case forInRight");
// lodash.forInRight(new foo(), (value, key) => {
//   console.log(value);
// });
// console.log("forOwn");
// lodash.forOwn(new foo(), (value, key) => {
fork icon0
star icon0
watch icon0

+ 4 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const _ = require("lodash");

const obj = {
  a: 1,
  b: 2,
  c: 3,
};

// Define a callback function to execute for each property
function callback(value, key, object) {
  console.log(`${key}: ${value}`);
}

// Iterate over the object's properties in reverse order
_.forInRight(obj, callback);

Output: makefile Copy code

Other functions in lodash

Sorted by popularity

function icon

lodash.get is the most popular function in lodash (7670 examples)