135-1821-9792

javascript表格排序原理

  1. 代码:
    var arr = new Array(
        3,2,6,1,5
    )
    var flag = true
    function mySort(arr){
    if(flag){
        arr = arr.sort(function(a,b){
            return a-b
        })
    }else{
        arr = arr.sort(function(a,b){
            return b-a
        })
    }
    flag = !flag
    return arr
    }
    mySort(arr)
    console.log(arr)
    mySort(arr)
    console.log(arr)
    mySort(arr)
    console.log(arr)
  2. 输出:
    [ 1, 2, 3, 5, 6 ]
    [ 6, 5, 3, 2, 1 ]
    [ 1, 2, 3, 5, 6 ]

新闻标题:javascript表格排序原理
分享路径:http://kswsj.com/article/pjseoh.html

其他资讯



Copyright © 2009-2022 www.kswsj.com 成都快上网科技有限公司 版权所有 蜀ICP备19037934号