Skip to content
Related Articles
Open in App
Not now

Related Articles

JavaScript Symbol.iterator Property

Improve Article
Save Article
  • Difficulty Level : Medium
  • Last Updated : 01 Apr, 2021
Improve Article
Save Article

It is an object of Iterables which is also a kind of generalized arrays. Iterables that make any object easier to use in a for..of the loop. We know that arrays are iterative in nature but other than that, there are also several objects which are used for the iterative purpose. Suppose if any object which is not an array but does possess a group of the list, set, etc then for..of can be used to iterate it.

We use for..of loop to represent a range object of any interval. It decides the range in which the for..of the loop will work and iterate the loop.

We will use a method Symbol.iterator (an in-built method in JavaScript) to iterate the range object which is mentioned above. The steps in which this method works:

  1. Once for..of loop starts it checks the error first, if it is not found then it accesses the method and the object with the method.
  2. After that for..of loop will run over the object.
  3. To take the next upcoming value, it calls the next() method for that output object.
  4. The values returned will be of the form {done: Boolean, value: any}. When done=true is returned then the loop will be considered as the complete one.




  • The range will not have the next() method on its own.
  • When we call to the range[Symbol.iterator](), an iterator is formed and the method next() will generate the value for further iterations.



let range = {
  from: 2,
  to: 7
range[Symbol.iterator] = function() {
  return {
    now: this.from,
    next() {
      if ( <= this.end) {
        return { done: false, value: };
      } else {
        return { done: true };
for (let i of range) {


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!