* Add sim test for any type * Fix doc comments to match code * Add array ascription tests * Commit new test output * Fix to not panic when type is undefined * Fix to not panic on use of the any type * Update test and generated output * Fix error message after rebase * Fix subtype of any * Fix KCL to use new keyword args * Fix to not nest MixedArray in HomArray * Update output * Remove all creation of MixedArray and use HomArray instead * Rename MixedArray to Tuple * Fix to coerce arrays the way tuples are done * Restructure to appease the type signature extraction * Fix TS unit test * Update output after switch to HomArray * Update docs * Fix to remove edge case when creating points * Update docs with broken point signature * Fix display of tuples to not collide with arrays * Change push to an array with type mismatch to be an error * Add sim test for push type error * Fix acription to more general array element type * Fix to coerce point types * Change array push to not error when item type differs * Fix coercion tests * Change to only flatten as a last resort and remove flattening tuples * Contort code to appease doc generation * Update docs * Fix coerce axes * Fix flattening test to test arrays instead of tuples * Remove special subtype case for singleton coercion
47 lines
26 KiB
Markdown
47 lines
26 KiB
Markdown
---
|
|
title: "push"
|
|
subtitle: "Function in std::array"
|
|
excerpt: "Append an element to the end of an array."
|
|
layout: manual
|
|
---
|
|
|
|
Append an element to the end of an array.
|
|
|
|
```kcl
|
|
push(
|
|
@array: [any],
|
|
item: any,
|
|
): [any]
|
|
```
|
|
|
|
Returns a new array with the element appended.
|
|
|
|
### Arguments
|
|
|
|
| Name | Type | Description | Required |
|
|
|----------|------|-------------|----------|
|
|
| `array` | [`[any]`](/docs/kcl-std/types/std-types-any) | The array which you're adding a new item to. | Yes |
|
|
| `item` | [`any`](/docs/kcl-std/types/std-types-any) | The new item to add to the array | Yes |
|
|
|
|
### Returns
|
|
|
|
[`[any]`](/docs/kcl-std/types/std-types-any)
|
|
|
|
|
|
### 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",
|
|
)
|
|
```
|
|
|
|

|
|
|
|
|