A typical reverse for loop:
for(let i = arr.length - 1, item = arr[i]; i >= 0; i--){
let item = arr[i];
do thing with item
}
I was thinking I could remove the brackets by assigning the item variable in the for declaration
for(let i = arr.length - 1, item = arr[i]; i >= 0; i--)
do thing with item
But it doesn't work and I didn't understand why. Then after some careful look at the code, I realised that the item variable is set only once. So I changed it to
for(let item, i = arr.length - 1; i >= 0; i--, item = arr[i])
do thing with item
But now item appears undefined and can't figure out why because the code appears correct
itemwont have a value.