props-iterator

Iterates all properties (owned and inherited) of an object.

Usage no npm install needed!

<script type="module">
  import propsIterator from 'https://cdn.skypack.dev/props-iterator';
</script>

README

props-iterator

Iterates all properties (owned and inherited) of an object.

Installation

Requires Node.js 7.0.0 or above.

npm i props-iterator

API

The module exports a single function.

Parameters

  1. Bindable: obj (object): The object whose properties you want to iterate.
  2. Object argument:
    • Optional: own (boolean): If set to true, only the object’s “own” properties are iterated. If omitted or if set to false, both owned and inherited properties are returned.
    • Optional: enumOnly (boolean): If set to true, only properties defined with the enumerable flag will be iterated.

Return Value

An iterator that yields two-element key-value-pair arrays.

Example

const props = require('props-iterator')

const iter = props({key: 'value'}, {own: true})
iter.next().value // ['key', 'value']
iter.next().done // true

Related