我想要一个类似于Array.pop()的Array方法,它表现出先入先出行为,而不是本机FILO行为.有一个简单的方法吗?
想象一下javascript控制台:
>> array = []; >> array.push(1); >> array.push(2); >> array.push(3); >> array.fifopop(); 1 <-- array.pop() yields 3, instead
Deblaton Jea.. 24
你可以使用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/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift
你可以使用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/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift