To get a subset of an Array in JS, use the .slice
method
Array.slice(startIndexInclusive, endIndexExclusive)
Reference:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
Example:
const a = ['Hello', 'World', 'Foo', 'Bar']
console.log(a.slice(0, 1)) // prints: ['Hello']
console.log(a.slice(0, 2)) // prints: ['Hello', 'World']
console.log(a.slice(2, a.length) // prints: ['Foo', 'Bar']
console.log(a.slice(0, a.length) // prints the entire array ... note: this would be pointless, as you could just print 'a' itself
So, to incorporate your amountOfItems
you'd have to just do
a.slice(startIndex, startIndex + amountOfItems)
I hope this helps somewhat.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…