sort Json data array custom list - Javascript JSon

Javascript examples for JSon:JSon Convert

Description

sort Json data array custom list

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(){//from  ww w . j a  v  a 2s.  co m
var objName = [{id:1, name:"one"},{id:2, name:"two"}, {id:3, name:"three"}];
var sortById = [1,3,2];
var result = [];
sortById.forEach(function(id) {
    result = result.concat(objName.filter(function(i) {
        return i.id == id;
    }));
});
console.log(result);
    }

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

Related Tutorials