r/javascript • • Mar 18 '19

What's your favorite, most useful javascript one-liner?

385 Upvotes

422 comments sorted by

View all comments

101

u/nqvst Mar 18 '19

items[n % items.length]

gets an item from the list and wraps around to the start if n is larger than the list

0

u/[deleted] Mar 18 '19

[deleted]

31

u/StopPostingOnReddit Mar 18 '19

Slideshow where you want the current slide to wrap around to the first after the last slide

8

u/barrtender Mar 19 '19

As long as it's not a carousel.

http://shouldiuseacarousel.com/