UNPKG

object-iterable

Version:

Create a new object containing the same properties (through assignment) of another object along with an @@iterator method can make use of the default iteration behavior (such as for-of) that built-in iterables like Array or Map have.

22 lines (16 loc) 363 B
function objectIterator(obj) { const iterableObj = { [Symbol.iterator]: function() { const keys = Object.keys(this); let i = 0; return { next: () => ({ value: this[keys[i++]], done: i > keys.length }) }; } }; return Object.assign(iterableObj, obj); } module.exports = objectIterator;