Currently, I map my JSON file like this:
var sortedData = $.map(response.data, function(data, index) {
return [data];
});
This works fine. But the key (index) is missing. How can I add it?
Content of the JSON file:
{
"index": 5,
"timestamp": 1570438008,
"data": {
"12": [
"Title 2",
"Description 2"
],
"10": [
"Title 1",
"Description 1"
]
}
}
After $.map I'd like to sort it (data attribute). I did it like this:
sortedData.sort(function(a, b) {
return (b[3] < a[3]) ? -1 : 1;
});
Expected output:
"12": [
"Title 2",
"Description 2"
],
"10": [
"Title 1",
"Description 1"
]
.. and NOT like this:
"10": [
"Title 1",
"Description 1"
],
"12": [
"Title 2",
"Description 2"
]