Peeking the element from the front of the queue

Now, let's implement some additional helper methods for our class. If we want to know what the front element of our queue is, we can use the peek method. This method will return the item from the front of the queue (using the lowestCount as a key to retrieve the element value):

peek() {  if (this.isEmpty()) {    return undefined;  }  return this.items[this.lowestCount];} 

Get Learning JavaScript Data Structures and Algorithms - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.