FIFO behavior for Array.pop in javascript? -
this question has answer here:
- how implement stack , queue in javascript? 15 answers
i want array method similar array.pop() exhibits first in first out behavior, instead of native filo behavior. there easy way so?
imagine javascript console:
>> array = []; >> array.push(1); >> array.push(2); >> array.push(3); >> array.fifopop(); 1 <-- array.pop() yields 3, instead
you can use array.prototype.shift()
>> array = []; >> array.push(1); >> array.push(2); >> array.push(3); >> array.shift(); //outputs 1 , removes array https://developer.mozilla.org/fr/docs/web/javascript/reference/objets_globaux/array/shift
Comments
Post a Comment