Skip to content

Instantly share code, notes, and snippets.

@jorgepinon
Created December 13, 2013 07:17
Show Gist options
  • Save jorgepinon/7940874 to your computer and use it in GitHub Desktop.
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)
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