首页 > 编程语言 > 详细

js简单对象List自定义属性排序

时间:2017-08-27 15:15:18      阅读:764      评论:0      收藏:0      [点我收藏+]
简单对象List自定义属性排序
    <script type="text/javascript">
        var objectList = new Array();
        function Persion(name,age){
            this.name=name;
            this.age=age;
            }
        objectList.push(new Persion(‘jack‘,20));
        objectList.push(new Persion(‘tony‘,25));
        objectList.push(new Persion(‘stone‘,26));
        objectList.push(new Persion(‘mandy‘,23));
        //按年龄从小到大排序
        objectList.sort(function(a,b){
            return a.age-b.age});
         //按年龄从大到小排序
    objectList.sort(function(a,b){
            return b.age-a.age});
    </script>

 

js简单对象List自定义属性排序

原文:http://www.cnblogs.com/qkabcd/p/7440292.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!