object-foreach
Version:
Executes a function on each of an objects own enumerable properties.
18 lines • 694 B
JavaScript
/**
* Executes a function on each of an objects own enumerable properties. The
* callback function will receive three arguments: the value of the current
* property, the name of the property, and the object being processed. This is
* roughly equivalent to the signature for callbacks to
* Array.prototype.forEach.
* @param {Object} obj The object to act on.
* @param {Function} callback The function to execute.
* @returns {Object} Returns the given object.
*/
function objectForeach(obj, callback) {
"use strict";
Object.keys(obj).forEach(function (prop) {
callback(obj[prop], prop, obj);
});
return obj;
};
module.exports = objectForeach;