back to Overview

_.mapObj()

Creates a new object with the same properties but different values using the given callback function.
Util module only.

Syntax Variants

_.mapObj(obj, callback)
_.mapObj(obj, callback, ctx)

Parameters

obj
the object to use
callback
The callback function(key, value) to invoke for each property.
key
The name of the current property.
value
The value of the current property.
this
The given context. If not set, the object itself.
(callback return value)
This value will replace the original value in the new object.
ctx (optional)
a context to pass to the callback as 'this'.
(return value)
the new object

Description

Creates a new object with the same properties but different values using the given callback function. The function is called for each property of the input object to provice a new value for the property.

Example

Increases the values of all properties.

var r = _.mapObj({a: 1, b: 5, c: 2}, function(key, value) {
    return value + 1;
});
// r is now {a: 2, b: 6, c: 2}

See also..

Comments

comments powered by Disqus

back to Overview

Functions