README
arreach
Do something with each matching key in an array of objects.
Usage
const arreach = require('arreach');
let arr = [
{
name: 'Dog',
sound: 'Woof'
},
{
name: 'Duck',
sound: 'Quack'
},
{
name: 'Cat',
sound: 'Meow'
}
];
arreach(arr, 'name', function (val) {
console.log(`On the farm there is a: ${val}`);
});
The above snippet would have the following output:
On the farm there is a: Dog
On the farm there is a: Duck
On the farm there is a: Cat
You can also get the parent object with an optional obj
parameter on the callback:
arreach(arr, 'name', function (val, obj) {
console.log(`On the farm there is a: ${val}... ${obj.sound}!`);
});
The above snippet would have the following output:
On the farm there is a: Dog... Woof!
On the farm there is a: Duck... Quack!
On the farm there is a: Cat... Meow!