javascript - Sorting a JSON Array based on key -


good day, trying sort json array based on dictionary value. before serialization, dictionary displayed in alphabetical order correct, once serialized, array sorted based on dictionary key. example is:

{[692:"!entry1"]}, {[5:"!entry2"]}, {[75:"!entry3"]} 

is sorted

{[5:"!entry2"]}, {[75:"!entry3"]}, {[692:"!entry1"]} 

any please

that's not valid json, , if were, wouldn't array, object. objects not sorted.

if array, sparse. json doesn't have way represent sparse arrays.

in javascript (no jquery required), can express sparse array this:

var = []; a[692] = "!entry1"; a[5]   = "!entry2"; a[75]  = "!entry3"; 

but noted, sorted key, not value (e.g., "!entry2", "!entry3", "!entry1").

neither json nor javascript has way sort basic types (arrays or objets) value of entries.

in json (or javascript), this:

[{"692":"!entry1"}, {"5":"!entry2"}, {"75":"!entry3"}] 

...which represents array of objects, each object has property name "75" has value giving "entry" strings. very hard work with.

another way be:

[     {key: "692", value: "!entry1"},     {key: "5",   value: "!entry2"},     {key: "75",  value: "!entry3"} ] 

which array of objects, each object has key property giving key, , value property giving value.


Comments