push

Adds one or more elements to the end of an array and returns that last element added. This method changes the length of the array.

Applies to

Array

Syntax

push(elt1, ..., eltN)

Parameters

elt1,...eltN

The elements to add to the end of the array.

Description

The behavior of the push method is analogous to the push function in Perl 4. Note that this behavior is different in Perl 5.

Example

The following code displays the myFish array before and after adding elements to its end. It also displays the last element added:

myFish = ["angel", "clown"];
Console.Write("myFish before: " + myFish);
pushed = myFish.push("drum", "lion");
Console.Write("myFish after: " + myFish);
Console.Write("pushed this element last: " + pushed);

This example displays the following:

myFish before: ["angel", "clown"]
myFish after: ["angel", "clown", "drum", "lion"]
pushed this element last: lion

See also

Array: pop, Array: shift, Array: unshift