英[ʃɪft] 美[ʃɪft]

vt.& vi. change; shift gears; remove; get rid of

vt. Change clothes of..., change (clothes); sell , sell; [computer] displace (data)

vi. (car) shift gears; change clothes; muddle through; make a living for oneself

n. Move, transfer, convert; change, change, Transform, replace, replace, swap, make it easier, substitute; (for cars, etc.) shifting

Third person singular: shifts Plural: shifts Present participle: shifting Past tense: shifted Past participle: shifted

javascript shift() method syntax

How to use the shift() method?

The shift() method can delete the first element from the array and return the value of the first element. The shift() method will change the length of the array.

Function: Used to delete the first element of the array and return the value of the first element.

Syntax: arrayObject.shift()

Description: If the array is empty, then the shift() method will not perform any operation. Returns undefined value. Please note that this method does not create a new array, but directly modifies the original arrayObject.

Return: The value of the original first element of the array.

Note: This method will change the length of the array. To remove and return the last element of an array, use the pop() method.

javascript shift() method example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script type="text/javascript">

    var arr = new Array(3)
    arr[0] = "George"
    arr[1] = "John"
    arr[2] = "Thomas"

    document.write(arr + "<br />")
    document.write(arr.shift() + "<br />")
    document.write(arr)

</script>

</body>
</html>

Run instance »

Click the "Run instance" button to view the online instance