2

我有这样的jsonarray事情:

  var jsonarr= [{"displayName":"Rachita Jain","phoneNumbers":[{"value":"(787) 989-6756"},{"value":"
    (897) 867-4666"}]},{"displayName":"Akanksha Mittal","phoneNumbers":[{"value":"(678) 456-4677"}]}] 

我想使用基于displayName.

4

1 回答 1

1

使用排序函数数组:

var jsonarr = [{
    "displayName": "Rachita Jain",
    "phoneNumbers": [{
        "value": "(787) 989-6756"
    }, {
        "value": "(897) 867-4666"
    }]
}, {
    "displayName": "Akanksha Mittal",
    "phoneNumbers": [{
        "value": "(678) 456-4677"
    }]
}];



jsonarr.sort(function (item1, item2) { return (item1.displayName > item2.displayName) ? 1 : -1 });

console.log(jsonarr);

见小提琴

于 2013-07-04T08:26:11.937 回答