Files
lodash/mapObject.js
John-David Dalton e2941dda3b Fix typos.
2017-04-16 08:57:46 -05:00

30 lines
781 B
JavaScript

/**
* Creates an array of values by running each property of `object` thru
* `iteratee`. The iteratee is invoked with three arguments: (value, key, object).
*
* @since 5.0.0
* @category Object
* @param {Object} object The object to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the new mapped array.
* @example
*
* function square(n) {
* return n * n
* }
*
* map({ 'a': 4, 'b': 8 }, square)
* // => [16, 64] (iteration order is not guaranteed)
*/
function mapObject(object, iteratee) {
const props = Object.keys(object)
const result = new Array(props.length)
props.forEach((key, index) => {
result[index] = iteratee(object[key], key, object)
})
return result
}
export default mapObject