Created
December 13, 2013 07:17
-
-
Save jorgepinon/7940874 to your computer and use it in GitHub Desktop.
create an array of objects from a JSON object (useful for harpjs _data.json)
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
var dataJson = {}, | |
dataArray = []; | |
// assuming a JSON structure like this: | |
dataJson = { | |
"key1": { | |
"prop1": "val1", | |
"prop2": "val2" | |
}, | |
"key1": { | |
"prop1": "val3", | |
"prop2": "val4" | |
} | |
} | |
for (var key in dataJson) { | |
if (!dataJson.hasOwnProperty(key)) { | |
//The current property is not a direct property of p | |
continue; | |
} | |
dataArray.push(dataJson[key]); | |
} | |
console.log(dataArray[1]); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment