Created
November 19, 2013 08:05
-
-
Save nickarthur/7541926 to your computer and use it in GitHub Desktop.
ARRAY TO OBJECT and OBJECT TO ARRAY conversion
CLOUDPARTY cloudparty
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
//cloudparty array to object and object to array | |
///////////////////////////////////////////////////////////////////////////////////////////// | |
//array to object | |
results_total: arrayToObject(resultsTotalArray), | |
results_current: arrayToObject(resultsCurrentArray) | |
function arrayToObject(arr) { | |
var obj = {}; | |
for (var i = 0; i < arr.length; i++) { | |
obj[arr[i][0]] = { name: arr[i][1], time_finished: arr[i][2] }; | |
} | |
return obj; | |
} | |
////////////////////////////////////////////////////////////////////////////////////////////// | |
//object to array | |
// Convert the total race results object into an array for sorting by time | |
resultsTotalArray = objectToArray(globalStateData.results_total); | |
// Convert the current race results object into an array for sorting by time | |
resultsCurrentArray = objectToArray(globalStateData.current_racers); | |
function objectToArray(obj) { | |
var arr = []; | |
for (var key in obj) { | |
arr.push([key, obj[key].name, obj[key].time_finished]); | |
} | |
return arr; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment