Files
lodash/mapObject.js
John-David Dalton 0bdc73195f Split map out.
2017-04-15 23:22:49 -05:00

30 lines
782 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