Paginate Javascript array

前端 未结 7 1814
庸人自扰
庸人自扰 2020-12-02 08:55

I am trying to write a Javascript function that takes an array, page_size and page_number as parameters and returns an array that mimi

相关标签:
7条回答
  • 2020-12-02 09:53

    Hey I'm sorry I'm a bit late but we can use the Array.splice(start, end) method except this is much simpler

    const page = 2
    const step = 2;
    const start = page * step - step;
    const end = start + step;
    
    const array = [1,2,3,4,5,6]
    console.log(array.splice(start, end))
    
    0 讨论(0)
提交回复
热议问题