Provides a secure function to iterate over keys and values. Usage is similar to Javascript Array.prototype.forEach
npm install foreach-objectThis library provides secure foreach functionality for objects.
Mainly focuses on avoiding some common errors that encounter with javascript for-in iterations, such as iterating through prototype properties.
Method signature is similar to Array.prototype.forEach.
```
npm i foreach-object
After installing foreach-object module, you can use either import syntax of ES6 or require syntax of node to make this library available in your file.
#### Using import
``
import each from 'foreach-object';
const object = {
firstName: 'Arosha',
lastName: 'Sum',
country: 'Australia'
};
each(object, (value, key, object) => {
console.log(key + ': ' + value);
});
// Console log output will be:
// firstName: Arosha
// lastName: Sum
// country: Australia
#### Using require
`
const each = require('foreach-object');
const object = {
firstName: 'Arosha',
lastName: 'Sum',
country: 'Australia'
};
each(object, (value, key, object) => {
console.log(key + ': ' + value);
});
// Console log output will be:
// firstName: Arosha
// lastName: Sum
// country: Australia
``
This library will iterate through object's own properties only. Therefore, prototype properties will be ignored.