| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/shift | [Back] [Original] |
Get to know MDN better
const array = [1, 2, 3];
const firstElement = array.shift();
console.log(array);
// : Array [2, 3]
console.log(firstElement);
// : 1
shift()
shift() 1 1 length 0 undefined
pop() shift()
shift() this this arr.slice(1)
myFish
const myFish = ["angel", "clown", "mandarin", "surgeon"];
console.log("myFish :", myFish);
// myFish : ['angel', 'clown', 'mandarin', 'surgeon']
const shifted = myFish.shift();
console.log("myFish :", myFish);
// myFish : ['clown', 'mandarin', 'surgeon']
console.log(":", shifted);
// : angel
shift() while
const names = ["Andrew", "Tyrone", "Paul", "Maria", "Gayatri"];
while (typeof (i = names.shift()) !== "undefined") {
console.log(i);
}
// Andrew, Tyrone, Paul, Maria, Gayatri
shift() this length 0 length 0 undefined 0 1 length - 1 length 1
const arrayLike = {
length: 3,
unrelated: "foo",
2: 4,
};
console.log(Array.prototype.shift.call(arrayLike));
// undefined
console.log(arrayLike);
// { '1': 4, length: 2, unrelated: 'foo' }
const plainObj = {};
// length length 0
Array.prototype.shift.call(plainObj);
console.log(plainObj);
// { length: 0 }
| ECMAScript 2027 LanguageSpecification # sec-array.prototype.shift |
Arrayat()concat()copyWithin()entries()every()fill()filter()find()findIndex()findLast()findLastIndex()flat()flatMap()forEach()includes()indexOf()join()keys()lastIndexOf()map()pop()push()reduce()reduceRight()reverse()shift()slice()some()sort()splice()toLocaleString()toReversed()toSorted()toSpliced()toString()unshift()values()with()[Symbol.iterator]()Object/Function| Web Proxy Viewer | New URL | Original Page |