The iterator protocol defines how to produce a sequence of values from an object. An object becomes an iterator when it implements a next() method. The next() method must return an object with two properties: value : The value returned by the iterator (Can be omitted if done is true) done : true if the iterator has completed false if the iterator has produced a new value Example:

// Create an Object
myNumbers = {};

// Make it Iterable
myNumbers[Symbol.iterator] = function() {
  let n = 0;
  done = false;
  return {
    next() {
      n += 10;
      if (n == 100) {done = true}
      return {value:n, done:done};
    }
  };
}

let text = ""
for (const num of myNumbers) { 
  text += num +"
" } //Output:- myNumbers iterator will iterate till n is 100