I have this json object:
obj = {
"name":
{
"display": "Name",
"id": "name",
"position": 3
},
"type":
{
"id": "type",
"position": 0
},
"id":
{
"display": "ID",
"id": "id",
"position": 1
}
"key":
{
"display": "Key",
"id": "key",
"position": 2
},
}
Is it possible to sort it based on their position numbers, without converting it to an array? I tried to convert it but it changes the format (it deletes the name,type,id,key) and I don't want this.. It should stay as it is (the format) but just in order based on their position.
what i did:
var array = $.map(obj, function(value, index) {
return [value];
});
array.sort(function(a,b){
return a.position - b.position;
});
obj= JSON.stringify(array);
obj= JSON.parse(obj);