javascript中Array.pop的FIFO行为? [英] FIFO behavior for Array.pop in javascript?
本文介绍了javascript中Array.pop的FIFO行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要一个与Array.pop()类似的Array方法,该方法表现出先进先出行为,而不是本机FILO行为。有简单的方法吗?
I want an Array method similar to Array.pop() that exhibits First In First Out behavior, instead of the native FILO behavior. Is there an easy way to do so?
想象一个JavaScript控制台:
Imagine a javascript console:
>> array = [];
>> array.push(1);
>> array.push(2);
>> array.push(3);
>> array.fifopop();
1 <-- array.pop() yields 3, instead
推荐答案
您可以使用array.prototype.shift()
You can use array.prototype.shift()
>> array = [];
>> array.push(1);
>> array.push(2);
>> array.push(3);
>> array.shift(); //outputs 1 and removes it from the array
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/ Global_Objects / Array / shift
这篇关于javascript中Array.pop的FIFO行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文