in my for element of array
loop, I want to access the elements besides the current one. Specifically, the previous or next element. I would also like this to reach across the first/last element barrier. How can this be achieved?
ie. given:
my_fruits = ['apple', 'banana', 'grapes', 'blueberries']
for (const fruit of my_fruits) {
// When fruit === 'banana', I want to access 'apple',
// when fruit === 'blueberries' I want to access 'grapes'.
// Also when it's the last element, I want to acknowledge that and access the first.
}
Due to how I'm dealing with async/await
in this local, .forEach
is something I'd prefer to avoid.
Thanks