Skip to content

Instantly share code, notes, and snippets.

@tehnrd
Created January 29, 2015 13:55
Show Gist options
  • Save tehnrd/57b2915210d776a15998 to your computer and use it in GitHub Desktop.
Save tehnrd/57b2915210d776a15998 to your computer and use it in GitHub Desktop.
Convert Census Response to Objects
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