Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptLodash _.after() Method

Lodash _.after() Method

The Lodash _.after() method is opposite of Lodash _.before() method. This method is used to creates a function that invokes func once it’s called n or more times.

Syntax:

_.after(n, func)

Parameters: This method accepts two parameters as mentioned above and described below:

  • n: This parameter holds the number n that defines number of calls before func is invoked.
  • func: This parameter holds the function which will invoked.

Return Value: This method returns the new restricted function.

Below example illustrate the Lodash _.after() method in JavaScript.

Example 1: In this example we try to invoke the function 3 times but it will in invoke 3rd times only.




// Requiring the lodash library  
const _ = require("lodash"); 
  
// Applying _.after() method
var gfg = _.after(3, function () {
  console.log('Saved');
});
  
gfg(); // Print nothing
gfg(); // Print nothing
gfg(); // Print Saved


Output:

Saved

Example 2: In this example we try to invoke the function 2 times but it will in invoke 2nd times only.




// Requiring the lodash library  
const _ = require("lodash"); 
  
// Applying _.after() method
var gfg = _.after(2, function () {
  console.log('Successful');
});
  
gfg(); // Print nothing
gfg(); // Print Successful


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, neveropen 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!

RELATED ARTICLES

Most Popular

Recent Comments