Object forOf
Simple object iterator
Install
npm install object-forof --save
example
const forOf = // Explanation:const obj = input: // --> type in1: // --> port '1' // --> val // Calls: fn('input', 'in1', '1') in2: // --> port '2' // --> val // Calls: fn('input', 'in1', '2') output: // --> type out1: // --> port '1' // --> val // Calls: fn('output', 'out1', '1') out2: // --> port '2' // --> val // Calls: fn('output', 'out2', '2')
Given the above example you could use Object.keys
like this:
Object
Or a for in
loop
for let type in obj if obj for let port in objtype if objtype const val = objtypeport // do something with type, port, val
With forOf
:
If you return something other from the function than undefined
it will be added as a value within the returned array.
E.g.
Both result in:
type: 'input' val: '1' type: 'input' val: '2'
Download
- Development version: https://npmcdn.com/object-forof/dist/forOf.js
- Minified version: https://npmcdn.com/object-forof/dist/forOf.min.js