add item at the back of the queue and take off old items from the front of the queue in array - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

add item at the back of the queue and take off old items from the front of the queue in array

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from w  w  w. j  a  va  2 s .c  o  m*/
function nextInLine(arr, item) {
  arr.push(item);
  return arr.shift();
}
console.log(nextInLine([], 1)); // 1
console.log(nextInLine([2], 1)); // 2
console.log(nextInLine([5,6,7,8,9], 1)); // 5
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials