Currently, am looping through an Array with the following code:
{allThrows.map((handThrow, index) => {
But this starts with index=0; how can I start and work down to 0 from allThrows.length-1 as the first element and decrement by 1 from there?
Currently, am looping through an Array with the following code:
{allThrows.map((handThrow, index) => {
But this starts with index=0; how can I start and work down to 0 from allThrows.length-1 as the first element and decrement by 1 from there?
there's 2 way:
-reverse()
you can reverse your array first then loop through it by allThrows.reverse().map(), and have in mind, this will reverse the original array. you can store it in a new variable first.
-reduceRight()
this method applies a function on currentValue and send the result (accumulator) to next step, backwards.
but you can ignore the passed result and use only currentValue.
like this:
allThrows.reduceRight((accumulator,currentValue)=>{
console.log(currentValue)
return null
})