UK [ʌn'ʃɪft] US [ʌn'ʃɪft]

vi. Release the font change key on the typewriter or keyboard

javascript unshift() method syntax

Function:Add one or more elements to the beginning of the array and return the new length.

Syntax: arrayObject.unshift(newelement1,newelement2,....,newelementX)

Parameters: newelement1 Required. The first element added to the array. newelement2 Optional. The second element added to the array. newelementX Optional. Several elements can be added.​

Return: The new length of arrayObject.

Description: The unshift() method will insert its parameters into the head of arrayObject and move the existing elements to higher subscripts sequentially to leave room for space. The first argument to the method will become the new element 0 of the array, if there is a second argument it will become the new element 1, and so on. Please note that the unshift() method does not create a new creation, but directly modifies the original array.

Note: This method will change the length of the array. The unshift() method does not work correctly in Internet Explorer! To add one or more elements to the end of an array, use the push() method.

javascript unshift() 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()
    arr[0] = "George"
    arr[1] = "John"
    arr[2] = "Thomas"

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

</script>

</body>
</html>

Run instance »

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