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:
- n: This parameter holds the number n that defines the number of calls that function is no longer invoked.
- func: This parameter holds the function which will be invoked.
Return Value:
This method returns the new restricted function.
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
const _ = require("lodash");
let gfg = _.before(3, function () {
console.log('Saved');
});
gfg();
gfg();
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
const _ = require("lodash");
let gfg = _.before(2, function () {
console.log('Successful');
});
gfg();
gfg();
|
Output:
Successful
Reference: https://docs-lodash.com/v4/before/
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 :
27 Oct, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...