Is it possible to map only a portion of an array? (Array.map())

前端 未结 8 980
终归单人心
终归单人心 2020-12-31 07:16

I am building a project using React.js as a front-end framework. On one particular page I am displaying a full data set to the user. I have an Array which contains this full

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-31 07:36

    you could use the slice function before to map the array, it looks like you want to do some pagination there.

    var fruits = ['Banana', 'Orange', 'Lemon', 'Apple', 'Mango'];
    var citrus = fruits.slice(1, 3);
    
    // fruits contains ['Banana', 'Orange', 'Lemon', 'Apple', 'Mango']
    // citrus contains ['Orange','Lemon']

提交回复
热议问题