[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/shift [Back]  [Original]

Array.prototype.shift() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Array.prototype.shift()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.

shift() , . .

In this article

const array1 = [1, 2, 3];

const firstElement = array1.shift();

console.log(array1);
// Expected output: Array [2, 3]

console.log(firstElement);
// Expected output: 1

js
arr.shift();

. undefined .

shift 0 . . length 0 undefined .

shift ; . . (Objects which do not contain a length property reflecting the last in a series of consecutive, zero-based numerical properties may not behave in any meaningful manner.)

myFish . .

js
var myFish = ["angel", "clown", "mandarin", "surgeon"];

console.log("myFish before: " + myFish);
// " myFish : angel,clown,mandarin,surgeon"

var shifted = myFish.shift();

console.log("myFish after: " + myFish);
// " myFish : clown,mandarin,surgeon"

console.log("Removed this element: " + shifted);
// "  : angel"

while shift()

shift() while . while , .

js
var names = ["Andrew", "Edward", "Paul", "Chris", "John"];

while ((i = names.shift()) !== undefined) {
  console.log(i);
}
// Andrew, Edward, Paul, Chris, John

Specification
ECMAScript 2027 LanguageSpecification
# sec-array.prototype.shift


Web Proxy Viewer  |  New URL  |  Original Page