javascript - Is there a way to method chain .push and .shift array methods? -


here's code:

var myarr = [1,2,3,4,5]; function queue(arr, item) {   return arr.push(item).shift(); } 

i'm attempting create function queue takes "array" , "item" arguments. need to

  1. add item onto end of array
  2. remove first element of array
  3. return element removed.

my code not working. can me figure out?

because arr.push returns length of array, can't chain shift that

simply this

function queue(arr, item) {   arr.push(item);   return arr.shift(); } 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -