I'm trying to parse JSON string with few arrays and some key:value pairs. I'm now able to get values from one array but I want to get values from the other array too. The arrays have same keys but I can't find out how to get data from the second array.
My jQuery script looks like this
$("a").click(function () {
var page = $(this).text();
console.log(page);
$.post("/services/gallery/getimage", {"path[]":[<%=path %>], "page": page}, function(data){
var length = data.previews.length;
console.log(length);
var html = "";
for(var i = 0; i < length; i++){
$.each(data.previews[i], function (index, value) {
html+= "<a href=\""+value+"\"><img src=\""+value+"\" alt=\""+index+"\" /></a>";
console.log("index: "+index);
console.log("value: "+value);
console.log(data.heights[i].index);
});
}
$("#gallery").html(html);
});
});
I've also tried some modifications of this console.log(data.heights[i].index); but still no usable result.
The console output is
1
15
index: index1
value: /some/path
undefined
index: index2
value: /some/paht
undefined
and the JSON string looks like this
{
"previews": [
{
"index1": "/some/path"
},
{
"index2": "/some/path"
}
],
"heights": [
{
"index1": "67"
},
{
"index2": "103"
}
]
}
I'll have more arrays with same indexes so it'll be great if it'll be possible to parse it in one for. Thanks for any help
EDIT: Names of attributes are dynamic not static. It can be whatever, not just index1, index2, ...