Lodash _.after() method is opposite of Lodash _.before() method. This method is used to create a function that invokes function once it’s called n or more times.
Syntax:
_.after(n, func);
Parameters:
- n: This parameter holds the number n that defines the number of calls before func is invoked.
- func: This parameter holds the function that will invoked.
Return Value:
This method returns the new restricted function.
Example 1: In this example, we try to invoke the function 3 times but it will invoke 3rd time only.
javascript
const _ = require( "lodash" );
let gfg = _.after(3, function () {
console.log( 'Saved' );
});
gfg();
gfg();
gfg();
|
Output:
Saved
Example 2: In this example, we try to invoke the function 2 times but it will in invoke 2nd times only.
javascript
const _ = require( "lodash" );
let gfg = _.after(2, function () {
console.log( 'Successful' );
});
gfg();
gfg();
|
Output:
Successful
Reference: https://docs-lodash.com/v4/after/
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!
Last Updated :
03 Nov, 2023
Like Article
Save Article