JavaScript - Is it possible to limit the results given by a forEach loop?
foreach, javascript
Solution
You could use `Array#slice` with negative value for the last items.
array.slice(-5).forEach()
Problem
I have a very long JSON `array` that I fetch using a `forEach` loop where I need to display only the last 5 elements. ``` array.forEach(showOnlyFiveElements => { //only 5 elements should be show here }); ``` Can't it be done using a forEach ? Or I should go for something different?