028-86922220

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

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://www.tsicrk.com/article/pjseoh.html

其他资讯

让你的专属顾问为你服务

0.7010s