Object.map.js
Array.map
for Object
in JavaScript. Map both an object’s keys and values.
Usage
By default, will allow calling Object.map
(obviously, as a non-enumerable property).
If you're terrified about augmenting prototypes of natives zomg ruin on us all, just set the shouldAugmentObjectPrototype
param to false
on the last line. The enclosing IEFE will then return the mapObject
function with the source object as its first parameter, so you can call it however you want.
Object.map(valueMapper, keyMapper);
Example
var source = { a: 1, b: 2 };
function sum(x) { return x + x }
source.map(sum);
source.map(undefined, sum);
source.map(sum, sum);
License
MIT: Do whatever you want as long as you don't sue me nor prevent others to reuse this piece of software.
Also, credit is always appreciated ;)