- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Add elements to a Queue using Javascript
Enqueuing elements to a Queue means adding them to the end of the array. We are taking the end of the container array to be the tail of the queue as we'll perform all insertions operations with respect to it.
So we can implement the enqueue function as follows −
Example
enqueue(element) { // Check if Queue is full if (this.isFull()) { console.log("Queue Overflow!"); return; } // Since we want to add elements to end, we'll just push them. .container.push(element); }
You can check if this function is working fine using −
Example
let q = new Queue(2); q.enqueue(1); q.enqueue(2); q.enqueue(3); q.display();
Output
This will give the output −
Queue Overflow! [ 1, 2 ]
- Related Articles
- Remove elements from a queue using Javascript
- Add elements to a PriorityQueue using Javascript
- Add elements to a Set using Javascript
- Add elements to a linked list using Javascript
- Add elements to a hash table using Javascript
- Peeking elements from a Queue in Javascript
- How to add HTML elements dynamically using JavaScript?
- Creating a Priority Queue using Javascript
- Add elements to a Dictionary in Javascript
- Clearing the elements of the Queue in Javascript
- Creating a Queue in Javascript
- How to add a tooltip to a div using JavaScript?
- How to add rows to a table using JavaScript DOM?
- How to push and pop elements in a queue in Ruby?
- Stack and Queue in Python using queue Module

Advertisements