Skip to content

Instantly share code, notes, and snippets.

@smalljam
Created May 19, 2011 13:18
Show Gist options
  • Save smalljam/980730 to your computer and use it in GitHub Desktop.
Save smalljam/980730 to your computer and use it in GitHub Desktop.
helper
// (obj, ['a', 'b', {'c':'b'}, 'e', 'f']) > {a:,b:,c:,e:,f:}
function mapper (obj, fields) {
var newObj = {};
for(var i = 0, cnt = fields.length; i<cnt; i++) {
var f = fields[i];
if(typeof f == 'string') {
newObj[f] = obj[f]
} else {
for(var k in f) {
newObj[k] = obj[ f[k] ];
}
}
}
return newObj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment