In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the method of js basic queue, which is very detailed and has certain reference value. Friends who are interested must finish reading it.
1. Add an element (enqueue) at the end of the queue.
2. Delete the element (dequeue) in the queue header.
3. Check the elements of the queue header (front).
4. Check whether the queue is empty (isEmpty).
5. Check the length of the queue (size).
6. View queue (print).
Example
Function Queue () {/ / initialize the queue (implemented using an array) var items = []; / / join the queue this.enqueue = function (ele) {items.push (ele);}; / / dequeue this.dequeue = function () {return items.shift ();}; / / return the first element this.front = function () {return items [0];} / / whether the queue is empty this.isEmpty = function () {return items.length = = 0;}; / / clear queue this.clear = function () {items = [];}; / / return queue length this.size = function () {return items.length;}; / / View queue this.show = queue () {return items;} } var queue = new Queue (); queue.enqueue ("hello"); queue.enqueue ("world"); queue.enqueue ("css"); queue.enqueue ("javascript"); queue.enqueue ("node.js"); console.log (queue.isEmpty ()); / / false console.log (queue.show ()); / / hello,world,css3,javascript,node.js console.log (queue.size ()); / / 5 console.log (queue.front ()) / / hello console.log (queue.dequeue ()); / / hello console.log (queue.show ()); / / 'world',' css', 'javascript',' node.js' console.log (queue.clear ()); console.log (queue.size ()); / / above are all the contents of the article "what are the methods of js basic queues"? thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.