I am trying to sort an array. For instance, given array a (below), I would like to return array b.
I know I can do a.sort()
, however, I don't want to sort on the actual array element, but on a property (s for this example) of the array element. How can this be accomplished?
Thank you
var a=[
{s:"ced",o:{obj:1}},
{s:"cde",o:{obj:2}},
{s:"ade",o:{obj:3}},
{s:"bde",o:{obj:4}}
]
var b=[
{s:"ade",o:{obj:3}},
{s:"bde",o:{obj:4}},
{s:"cde",o:{obj:2}},
{s:"ced",o:{obj:1}}
]