1 hour ago · Tech · 0 comments

What I call “wraparound” are repeatable indices on an array. The common use case is a carousel. Here’s how it’s done: const items = ["first", "middle", "last"]; const i = 0; // Our iterable index // "Next" -> const nextIndex = (i + 1) % items.length; // <- "Previous" const prevIndex = (i - 1 + items.length) % items.length;

No comments yet. Log in to reply on the Fediverse. Comments will appear here.