Question: *Is there any "python's Generator" equivalent in JavaScript?*  

*PS:*
Python's Generator is very memory efficient when we need to do **one time** iterate through a **big** array, hash...   

*"Generators are iterables, but you **can only read them once**. It's because they do not store all the values in memory, **they generate the values on the fly**"*

(Python's Generator explained in this thread: [What does the "yield" keyword do in Python?](https://stackoverflow.com/questions/231767/the-python-yield-keyword-explained) )

Answer: 
Not in a standard way. Some browsers [already implement](https://developer.mozilla.org/en/JavaScript/Guide/Iterators_and_Generators) python-style generators, but they require extensions that need to be explicitly activated.
There are proposals to [add generators](http://wiki.ecmascript.org/doku.php?id=proposals%3aiterators_and_generators) to a next version of the ECMAScript spec, but I wouldn't see that being useable very soon.

So far, the best you can do is to use the old school [external iterator](https://en.wikipedia.org/wiki/Iterator) pattern. It is just as powerful, although it is a pain to write in more complicated cases.
You can use the `yield` keyword. You can read more about it [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/yield) (MDN).

> 
> The yield keyword is used to pause and resume a generator function
> 
> 
> 

```js
function* range(n) {
    for (let i = 0; i < n; i++) {
        yield i;
    }
}

const generator = range(10);

console.log(generator.next());  // { value: 0, done: false }
console.log(generator.next());  // { value: 1, done: false }
...
console.log(generator.next());  // { value: 9, done: false }
console.log(generator.next());  // { value: undefined, done: true }

```

Notice the `*` after the `function` keyword.

It's widely supported now: [caniuse](https://caniuse.com/es6-generators), [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/yield#browser_compatibility)

---

TypeScript notation:

```
function* range(n: number): IterableIterator<number> {
    for (let i = 0; i < n; i++) {
        yield i;
    }
}

```