Open In App

Underscore.js _.iterators.K() Method

Last Updated : 01 Sep, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads