Sort JSON data table alphabetical and case insensitive - Javascript JSon

Javascript examples for JSon:JSon Object

Description

Sort JSON data table alphabetical and case insensitive

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {// w  ww .ja  v  a2s .com
var names = [
    {"FirstName":"A", "LastName":"Xb"},
    {"FirstName":"B", "LastName":"xa"},
    {"FirstName":"C", "LastName":"yc"}
];
names.sort(function(a, b) {
    return a.LastName.toLowerCase().localeCompare(
        b.LastName.toLowerCase()
    );
});
console.log(names);
    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials