Wednesday, July 3, 2024
HomeLanguagesJavascriptUnderscore.js _.iterators.K() Method

Underscore.js _.iterators.K() Method

With the help of _.iterators.K() method, we can get the function which when called generate a value from the given value by using this method.

Syntax:

_.iterators.K(value)

Parameter: This method accepts a single parameter as mentioned above and described below:

  • value: This parameter holds the given value.

Return:Return a single value at a time when function called.

Note: To execute the below examples, you have to install the underscore-contrib library by using this command prompt we have to execute the following command.

npm install underscore-contrib

Below examples illustrate the Underscore.js _.iterators.K() method in JavaScript:

Example 1: In this example, we can see that by using _.iterators.K() method, we are able to get the function which gives a value which is defined when iterator created by using this method.

Javascript




// Defining underscore contrib variable 
var _ = require('underscore-contrib');
  
var iter = _.iterators.K("Geeks for Geeks");
  
iter();


Output :

'Geeks for Geeks'

Example 2:

Javascript




// Defining underscore contrib variable 
var _ = require('underscore-contrib');
  
var pi = _.iterators.K(3.141592653589793);
  
pi();


Output :

3.141592653589793
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!

Ted Musemwa
As a software developer I’m interested in the intersection of computational thinking and design thinking when solving human problems. As a professional I am guided by the principles of experiential learning; experience, reflect, conceptualise and experiment.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments