Nodejs Array Iterator __iterator__(isKeys)

Here you can find the source of __iterator__(isKeys)

Method Source Code

/**// www .j ava  2s .  c o m
 * @fileOverview This file contains the JS 1.7+ Array iterator
 */

/**
 * Define an array iterator.
 * Using this we never need to hide properties from loops and both for and
 * for each loop syntax become available for looping over arrays while
 * guaranteeing that they will also always iterate in order.
 * 
 * @example
 * for each ( var item in [1, 2, 3] )
 *    print(item); // Prints 1 then 2 then 3
 * 
 * @example
 * for ( var key in [1, 2, 3] )
 *    print(key); // Prints 0 then 1 then 2
 * 
 * @methodOf Array
 * @name __iterator__
 */
Array.prototype.__iterator__ = function(isKeys) {
   for( let i = 0, l = this.length; i<l; ++i )
      yield isKeys ? i : this[i];
};

Related

  1. __iterator__(flag)
    "use strict";
    Array.prototype.__iterator__ = function (flag) {
      var len = this.length,
      item = 0;
      for (; item < len; i++) {
        yield flag ? item : this[item];
    };