Answer the question
In order to leave comments, you need to log in
How to process (sort) data received from an external json file?
I need to display in html the already sorted data from the json file
how to display it - there are no problems, but how to sort it depending on different data by key - I can’t find and understand,
advise who knows what
Answer the question
In order to leave comments, you need to log in
In the compare function, you specify the conditions for sorting objects. compare should always return 1|0|-1 and nothing else.
function compare(a,b) {
if (a.OrderID < b.OrderID)
return -1;
if (a.OrderID > b.OrderID)
return 1;
return 0;
}
arr.sort(compare);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question