I would like to sort a JSON items using Javascript by an other array, and to sort the rest of the items in alphabetically please.
I have an array of the order I want to get the JSON items:
var order = [3,9,50,7];
And a JSON with an "ID" key that I want to sort using the order array, and the rest of the non-matching items using the "Name" key please.
Here's the original JSON:
var data = [
{
"id": "9",
"title": "B"
},
{
"id": "63",
"title": "Z"
},
{
"id": "433",
"title": "D"
},
{
"id": "50",
"title": "A"
},
{
"id": "2",
"title": "G"
}
]
And this is the end result I want it to be like:
var data = [
{
"id": "9",
"title": "B"
},
{
"id": "50",
"title": "A"
},
{
"id": "433",
"title": "D"
},
{
"id": "2",
"title": "G"
},
{
"id": "63",
"title": "Z"
}
]