I'm trying to implement a slice method for an array, say you have a list of 7 items, but initially it shows 2 items. How would you show more items based on each function click ?
like show 3 more, show 2 more, show 1 more, until there is no more items to show.
https://jsbin.com/ratohehuyi/edit?js,console
I'm stuck on writing the logic, this is just pseudocode
const arr = ['blueberries', 'oranges', 'grapes', 'bananas', 'kiwis', 'apples', 'coconuts']
const arrNum = 2
console.log(arrNum)
const showMore = (arr) => {
return arr.slice(0, arrNum * 2 ) // this should increment i think based on each function click
}
console.log(showMore(arr))
The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place..slice