object-map
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/object-map package

1.0.2 • Public • Published

Map a function over the values of an Object to produce a new Object with the same keys.

The API is modelled after the native Array#map method.

Installation

$ npm install --save object-map

Example

var objectMap = require('object-map');
 
var target = {
  foo: 1,
  bar: 2
};
 
var result = objectMap(target, function(value) {
  return value * value;
});
// => {foo: 1, bar: 4}

API

objectMap(target, callback[, thisArg])

  • target an object who's properties are iterated using hasOwnProperty
  • callback a function producing a value of the new Object, taking three arguments:
    • currentValue the value currently associated with the key
    • key the current key
    • object the original object passed to objectMap
  • thisArg Optional. Value to use as this when executing callback.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i object-map

Weekly Downloads

509

Version

1.0.2

License

MIT

Last publish

Collaborators

  • xixixao