monners
3/25/2016 - 10:09 PM

Utility function for making Objects iterable

Utility function for making Objects iterable

function makeObjectIterable (obj) {
  obj[Symbol.iterator] = function *() {
    let properties = Object.keys(this);
    for (let p of properties) {
      yield this[p];
    }
  }
  
  return obj;
}