Last Updated : 15 Jul, 2025
Lodash _.before() method is the opposite of the Lodash _.after() method. This method is used to create a function that invokes func with the binding and arguments of the created function, while it’s called less than n times.
Syntax:_.before(n, func);Parameters:
Example 1: In this example, we will try to invoke the function 3 times but it will invoke 2 times only because of the lodash _.before() method.
JavaScript
// Requiring the lodash library
const _ = require("lodash");
// Using _.before() method
let gfg = _.before(3, function () {
console.log('Saved');
});
// It will print Saved
gfg();
// It will print Saved
gfg();
// It will print nothing
gfg();
Output:
Saved Saved
Example 2: In this example, we will try to invoke the function 2 times but it will invoke 1 time only because of the lodash _.before() method.
JavaScript
// Requiring the lodash library
const _ = require("lodash");
// Applying _.before() method
let gfg = _.before(2, function () {
console.log('Successful');
});
// It will print Successful
gfg();
// It will print nothing
gfg();
Output:
Successful
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4