Created
January 29, 2015 13:55
-
-
Save tehnrd/57b2915210d776a15998 to your computer and use it in GitHub Desktop.
Convert Census Response to Objects
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
convertCensusResToObject: function(arrayResponse){ | |
//The first row is always going to the the headers/keys | |
var headers = arrayResponse[0]; | |
//Define array that will contain results as javascript objects | |
var objectResponse = []; | |
//Loop through the "rows" of data, start at index 1 as 0 is header row | |
for(var i = 1; i < arrayResponse.length; i++){ | |
//Get the row we are looping over | |
var row = arrayResponse[i]; | |
//Loop through the "columns/headers" and build a javascript object | |
var rowObject = {}; | |
for(var j = 0; j < headers.length; j++){ | |
rowObject[headers[j]] = row[j]; | |
} | |
objectResponse.push(rowObject) | |
} | |
return objectResponse; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment