I have a JSON sent to the front-end after converting it from LinkedHashMap
. When I receive it using jQuery and iterate it through using $.each()
my insertion order is changed.
Suppose the object after iterating (using .each())
is {'1':'pqr','2':'abc'}
whereas the original insertion order on the servlet and when I get the JSON response is {'2':'abc'...}
(by value).
How would I preserve the order in each? I have read that array does it but having a hard time writing anything meaningful.
Code is like:
$.ajax({
type: "GET",
url: "Servlet",
dataType: "json",
success: function(data)
{
$.each(data, function(key, value){
// append to option element
});
}
});