Cross browser object map function (ES5 compatible)
I wanted a browser friendly solution, ES5 compatible, immutable, and with an API closer enough to Array.prototype.map
.
- Via Bower
$ bower install browser-object-map --save
- Via HTML
<script src="https://raw.githubusercontent.com/juliomatcom/browser-object-map/master/index.js"></script>
objectMap({ a: 1, b: [2, 3]}, function (value, key, object) {
return value + 1;
}, { deep: true });
// { a: 2, b: [3, 4] }
Note: It does not return always an array
, if argument is object
, it will return an object
objectMap(source, callback, [options]);
-
source
Type Object
Source object to copy properties -
callback
Type Function
Mapping functionSignature:
(sourceKey, sourceValue, source)
. -
options
Type ObjectOptional parameters
deep
Type Boolean
Recurse nested objects and arrays.
- Feature: Basic support
- Chrome: 5
- Firefox (Gecko): 4.0 (2.0)
- Internet Explorer: 9
- Opera: 12
- Safari: 5