Sort JSON by value [duplicate] Sort JSON by value [duplicate] json json

Sort JSON by value [duplicate]


I suggest to use Array#sort()

var data = [    { "id": "105", "name": "FIAT",    "active": true, "parentId": "1" },    { "id": "106", "name": "AUDI",    "active": true, "parentId": "1" },    { "id": "107", "name": "BMW",     "active": true, "parentId": "1" },    { "id": "109", "name": "RENAULT", "active": true, "parentId": "1" }];data.sort(function (a, b) {    return a.name.localeCompare(b.name);});document.write('<pre>' + JSON.stringify(data, 0, 4) + '</pre>');