47 lines
26 KiB
Markdown
47 lines
26 KiB
Markdown
---
|
|
title: "push"
|
|
excerpt: "Append an element to the end of an array."
|
|
layout: manual
|
|
---
|
|
|
|
Append an element to the end of an array.
|
|
|
|
Returns a new array with the element appended.
|
|
|
|
```js
|
|
push(
|
|
array: [KclValue],
|
|
elem: KclValue,
|
|
): KclValue
|
|
```
|
|
|
|
|
|
### Arguments
|
|
|
|
| Name | Type | Description | Required |
|
|
|----------|------|-------------|----------|
|
|
| `array` | [`[KclValue]`](/docs/kcl/types/KclValue) | | Yes |
|
|
| `elem` | [`KclValue`](/docs/kcl/types/KclValue) | Any KCL value. | Yes |
|
|
|
|
### Returns
|
|
|
|
[`KclValue`](/docs/kcl/types/KclValue) - Any KCL value.
|
|
|
|
|
|
### Examples
|
|
|
|
```js
|
|
arr = [1, 2, 3]
|
|
new_arr = push(arr, 4)
|
|
assert(
|
|
new_arr[3],
|
|
isEqualTo = 4,
|
|
tolerance = 0.1,
|
|
error = "4 was added to the end of the array",
|
|
)
|
|
```
|
|
|
|

|
|
|
|
|