* Show a more reasonable name in function docs Signed-off-by: Nick Cameron <nrc@ncameron.org> * Fix buggy docs for union types Signed-off-by: Nick Cameron <nrc@ncameron.org> * Make types in the docs signatures into links Signed-off-by: Nick Cameron <nrc@ncameron.org> --------- Signed-off-by: Nick Cameron <nrc@ncameron.org>
47 lines
27 KiB
Markdown
47 lines
27 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.
|
|
|
|
```kcl
|
|
push(
|
|
array: [[[KclValue](/docs/kcl/types/KclValue)]](/docs/kcl/types/[KclValue](/docs/kcl/types/KclValue)),
|
|
item: [KclValue](/docs/kcl/types/KclValue),
|
|
): [KclValue](/docs/kcl/types/KclValue)
|
|
```
|
|
|
|
|
|
### Arguments
|
|
|
|
| Name | Type | Description | Required |
|
|
|----------|------|-------------|----------|
|
|
| `array` | [`[KclValue]`](/docs/kcl/types/KclValue) | The array which you're adding a new item to. | Yes |
|
|
| `item` | [`KclValue`](/docs/kcl/types/KclValue) | The new item to add to the array | Yes |
|
|
|
|
### Returns
|
|
|
|
[`KclValue`](/docs/kcl/types/KclValue) - Any KCL value.
|
|
|
|
|
|
### Examples
|
|
|
|
```kcl
|
|
arr = [1, 2, 3]
|
|
new_arr = push(arr, item = 4)
|
|
assert(
|
|
new_arr[3],
|
|
isEqualTo = 4,
|
|
tolerance = 0.1,
|
|
error = "4 was added to the end of the array",
|
|
)
|
|
```
|
|
|
|

|
|
|
|
|