Function Namespace Pot.map
Defined in: <potlite.js>.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
Pot.map(object, callback, (context))
Creates a new object with the results of calling a
provided function on every element in object.
|
Function Namespace Detail
Pot.map(object, callback, (context))
Creates a new object with the results of calling a
provided function on every element in object.
This method like Array.prototype.map
function fuzzyPlural(single) {
return single.replace(/o/g, 'e');
}
var words = ['foot', 'goose', 'moose'];
debug(Pot.map(words, fuzzyPlural));
// @results ['feet', 'geese', 'meese']
var object = {foo: 'foo1', bar: 'bar2', baz: 'baz3'};
var result = Pot.map(object, function(value, key) {
return value + '00';
});
debug(result);
// @results {foo: 'foo100', bar: 'bar200', baz: 'baz300'}
- Parameters:
- {Array|Object|*} object
- A target object.
- {Function} callback
- A callback function.
- {*} (context)
- (Optional) Object to use as `this` when executing callback.
- Returns:
- {*} Return the result of each callbacks.