og

Js数组排序,上移下移置顶置底

Js数组排序.png

Js数组排序,上移下移置顶置底

置顶

        
  • 1
  • 2
  • 3
  • 4
  • 5
topRow(index,arr){ arr.unshift(arr[index]); arr.splice(index+1,1); return arr }

置底

        
  • 1
  • 2
  • 3
  • 4
  • 5
downRow(index,arr){ arr.push(arr[index]); arr.splice(index,1); return arr; }

上移

        
  • 1
  • 2
  • 3
  • 4
upRow(index,arr){ arr[index]=arr.splice(index-1, 1, arr[index])[0]; return arr }

下移

        
  • 1
  • 2
  • 3
  • 4
belowRow(index,arr){ arr[index]=arr.splice(index+1, 1, arr[index])[0]; return arr }

Article at   2021/08/30 16:41  Published  code  Category,viewed  69  times

Relevant tags:    JS 

Address:   https://www.kedong.me/article/56

Copyright Notice: Freely reproduced for non-commercial use