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);

  // return object with next method
  return {
    next: () => {

      let value;

      // values.shift() return `undefined`
      // when array is empty
      while (value = values.shift()) {
        return {
          value,
          done: false
        };
      }

      // if value is `undefined`, iterartion is done
      return {
        value,
        done: true
      };

    }
  };
}


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

console.log(...myObject);