After receiving JSON data from the server, I attempted to convert it into an array using:
JSON.parse(response.data.blocks)
However, I encountered this error:
SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at contentblocks.js?KHWUmpg:87149
at <anonymous>
I then tried to sort the blocks with:
let blocks = response.data.blocks.sort(function(a,b){
var x = a.order < b.order ? -1 : 1
return x
})
But got an error stating that "sort" does not exist. It seems I need to first convert the "blocks" object into an array so sorting can be done.
This is a snippet of the JSON sent by the server:
{
"status": "success",
"blocks": {
"0": {
"id": 50,
"content_id": 25,
...
},
"1": {
"id": 51,
"content_id": 25,
...
}
}
}