Super simple Javascript Queue class

It’s tempting, when in a hurry, to create a queue object in Javascript with an array. To enqueue something, push() it onto the array. To dequeue it, shift() it off. It works. But it’s slow, because shift() takes O(n) time where n is the length of the queue.

Kate Morely cooked up an almost-as-simple but much faster queue implementation. She was kind enough to release it to the public domain with a CC0 license.

I updated it to make it an ES6 class. And, I added a few more methods and an iterator to make it more useful for my purposes. Here’s a gist with my update, which you may use as you wish.

Leave a Comment