Related Articles

Related Articles

Underscore.js _.iterators.take() method
  • Last Updated : 19 Aug, 2020

With the help of _.iterators.take() method, we can get the values from the iteration function starting from 1 to numberToTake variable and return a value whenever iteration function is invoked by using this method.

Syntax:

_.iterators.take(iter, numberToTake)

Return: Return the value from iteration function.

Example 1:

In this example we can see that by using _.iterators.take() method, we are able to get the values from iteration function upto maximum value of numberToTake whenever we invoked the iteration function.



filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining underscore contrib variable 
var _ = require('underscore-contrib');
  
var iter = _.iterators.List(["Geeks", "for", "Geeks", "ABC", "XYZ"]);
  
var geek = _.iterators.take(iter, 3);
  
for(var i = 0; i < 3; i++) {
    console.log(geek());
}

chevron_right


Output:

Geeks
for
Geeks

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining underscore contrib variable 
var _ = require('underscore-contrib');
  
var iter = _.iterators.List([1, 2, 3, 4, 5, 6]);
  
var geek = _.iterators.take(iter, 3);
  
for(var i = 0; i < 3; i++) {
    console.log(geek());
}

chevron_right


Output:

1
2
3

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :