I’ve been playing around with some JavaScript code and come across an article which showed a really nice way of looping array items in JavaScript. Rather than having to write something like this:

A more elegant way would be like this by using the — operator like this:

One main drawback I can see is that we will be accessing the array items from back to front. We can counter that by using reverse() as shown:

Again that would require another bit of code which wouldn’t be needed doing it the “normal” way. This is just a bit of fun and playing around learning. Any comments or thoughts are more than welcome!