var obj = [
{ name: 'Lazslo', country: 'Philiphine' },
{ name: 'Cecilia', country: 'Vietnam' },
{ name: 'Margareta', country: 'China' }
];
The solution is We just have to create function like this:
function compare(a,b) {
if (a.name < b.name)
return -1;
if (a.name > b.name)
return 1;
return 0;
}
and apply the function as obj.sort(compare) or we can done it as inline script: objs.sort(function(a,b) {return (a.name > b.name) ? 1 : ((b.name > a.name) ? -1 : 0);} );
