Array.push(item) Last updated: 22. Jul 2024
Adds an item to the array (at the end) you are calling the method from.
Parameters
Name | Type | Description |
---|---|---|
item | object | Item to add to array at last position. |
Returns
The new length of the array.
Example
Code example (#JS)
#JS is mixed HTML (or other text file) with inline JavaScript with # starting and ending each inline statement.<b>Creating and outputing an array:</b>
#{
// Declare one item with a variable
var item = "test";
// Declare an empty array
var array = [];
// Adding some items from variables to the array
array.push(item);
array.push(item);
// Add a constant to the array
array.push("something else");
// Write the array to output
write(JSON.stringify(array));
}#
Output
The #JS code above produces the output shown below:<b>Creating and outputing an array:</b>
["test","test","something else"]