- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
Clearing the elements of the Queue in Javascript
We can clear the contents just by reassigning the container element to an empty array. For example,
clear() { this.container = []; }
Example
You can check if this function is working fine using:
let q = new Queue(2); q.enqueue(3); q.enqueue(4); q.display(); q.clear(); q.display();
Output
This will give the output:
[ 3, 4 ] [ ]
Advertisements