Created
December 1, 2016 23:47
-
-
Save jineeshjohn/0815d38aeb9aa5b41543833836bd59ea to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var responseJson = [ | |
{type: 'input', id: 'key1', styles:{display:'block', color: 'red'}, someprop:'abc', someotherprop:'bcd'}, | |
{type: 'radio', id: 'key2', styles:{display:'inline', color: 'blue'}, someprop:'xyz', someotherprop:'z'} | |
] | |
var parseResponse = function(response) { | |
var result = []; | |
for (var i=0; i<response.length; i++) { | |
var resultObj = { | |
type: response[i].type, | |
id: response[i].id, | |
styles: response[i].styles, | |
someprop: response[i].someprop | |
} | |
result.push(resultObj); | |
} | |
return result; | |
} | |
var parseResponse2 = function(response) { | |
return _.map(response, function(item){ | |
return _.pick(item, 'type', 'id', 'styles', 'someprop'); | |
}); | |
} | |
var result = parseResponse(responseJson); | |
var result = parseResponse2(responseJson); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment