Created
May 19, 2011 13:18
-
-
Save smalljam/980730 to your computer and use it in GitHub Desktop.
helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// (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