make-object-iterable

1.0.1 • Public • Published

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

/make-object-iterable/

    Package Sidebar

    Install

    npm i make-object-iterable

    Weekly Downloads

    3

    Version

    1.0.1

    License

    ISC

    Last publish

    Collaborators

    • tonykung06