andrewplummer/Sugar — Issue #69: Add Object.map method
Author: mlegenhausen
Created: 2011-12-02 12:24:09+00:00
State: open

Example code:

```
Object.map = function(obj, fn) {
var result = [];
Object.each(obj, function(key, value) {
result.push(fn(key, value));
});
return result;
}
```

What does it? Converts all key, value properties to a list. "map" cause I go trough all properties and map them to a new object. Example:

```
var obj = {foo: 'bar', bar: 'foo'}
var result = Object.map(obj, function(key, value) {
return {
key: key,
value: value
};
});
console.log(result); // [{ key: 'foo', value: 'bar'}, { key: 'bar', value: 'foo' }]
```

Useful when you does some map reduce work and used your object as hash map and want to convert it the key/value pairs in single objects.

Or is it already included?