In a javascript array, how do I get the last 5 elements, excluding the first element?

前端 未结 6 1946
自闭症患者
自闭症患者 2020-11-30 20:19
[1, 55, 77, 88] // ...would return [55, 77, 88]

adding additional examples:

[1, 55, 77, 88, 99, 22, 33, 44] // ...wo         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 20:28

    var y = [1,2,3,4,5,6,7,8,9,10];
    
    console.log(y.slice((y.length - 5), y.length))

    you can do this!

提交回复
热议问题