1.0.1 • Published 8 years ago

make-object-iterable v1.0.1

Weekly downloads
2
License
ISC
Repository
github
Last release
8 years ago

makeObjectIterable

a simple tool to make native JavaScript object iterable, e.g. used in for...of, spread operator

#Usage

##for...of

const originalObj = {
	prop1: 'value1',
	prop2: 'value2'
};

const iterableObj = makeObjectIterable(originalObj);

for (let value of iterableObj) {
	console.log(value);
}

##spread operator

const originalObj = {
	prop1: 'value1',
	prop2: 'value2'
};

const iterableObj = makeObjectIterable(originalObj);

console.log([...iterableObj]);

##array destructuring

const originalObj = {
	prop1: 'value1',
	prop2: 'value2'
};

const iterableObj = makeObjectIterable(originalObj);
const [prop1, prop2] = iterableObj;

console.log(prop1, prop2);