- 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
Clearing the elements of the PriorityQueue using 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 PriorityQueue(4); q.enqueue("Hello", 3); q.enqueue("World", 2); q.enqueue("Foo", 8); q.display(); q.clear(); q.display();
Output
This will give the output −
[ { data: 'World', priority: 2 }, { data: 'Hello', priority: 3 }, { data: 'Foo', priority: 8 } ] [ ]
- Related Articles
- Add elements to a PriorityQueue using Javascript
- Remove elements from a PriorityQueue using Javascript
- Peeking elements from a PriorityQueue using JavaScript
- Clearing the elements of the Queue in Javascript
- Clearing the elements of a Stack in Javascript
- Clearing the set using Javascript
- Clearing a Dictionary using Javascript
- The PriorityQueue Class in Javascript
- Clearing localStorage in JavaScript?
- Sorting elements of stack using JavaScript
- Finding the sum of all common elements within arrays using JavaScript
- PriorityQueue Class in Java Programming
- How to remove elements using the splice() method in JavaScript?
- Deep count of elements of an array using JavaScript
- Remove elements from array using JavaScript filter - JavaScript

Advertisements