JSFiddle - React, Tailwind, and code Playground

by Uday Hiwarale

JavaScript

Object.prototype[Symbol.iterator] = function() {

  // this refers to the object we are iterating
  // get object values
  const values = Object.values( this );

  // current index of iteration
  let index = -1;

  // return object with next method
  return {
    next: () => {
    
    	// increment index per iteration
      index++;
      
      // if index is gte length, no more value
      const done = index >= values.length;

      // return { value, done } object
      return {
        value: done ? undefined : values[ index ],
        done
      };
    }
  };
}


var myObject = { firstName: 'John', lastName: 'Doe', age: 26 };

/*for( let item of myObject ) {
	console.log( item );
}*/

console.log( ...myObject );