Files
modeling-app/docs/kcl-std/functions/std-array-pop.md
2025-06-19 17:08:46 +12:00

27 KiB

title, subtitle, excerpt, layout
title subtitle excerpt layout
pop Function in std::array Remove the last element from an array. manual

Remove the last element from an array.

arr = [1, 2, 3, 4]
new_arr = pop(arr)
assert(
  new_arr[0],
  isEqualTo = 1,
  tolerance = 0.00001,
  error = "1 is the first element of the array",
)
assert(
  new_arr[1],
  isEqualTo = 2,
  tolerance = 0.00001,
  error = "2 is the second element of the array",
)
assert(
  new_arr[2],
  isEqualTo = 3,
  tolerance = 0.00001,
  error = "3 is the third element of the array",
)

Arguments

Name Type Description Required
array [any; 1+] The array to pop from. Must not be empty. Yes

Returns

[any]

Description

Returns a new array with the last element removed.

Function signature

pop(@array: [any; 1+]): [any]

Examples

arr = [1, 2, 3, 4]
new_arr = pop(arr)
assert(
  new_arr[0],
  isEqualTo = 1,
  tolerance = 0.00001,
  error = "1 is the first element of the array",
)
assert(
  new_arr[1],
  isEqualTo = 2,
  tolerance = 0.00001,
  error = "2 is the second element of the array",
)
assert(
  new_arr[2],
  isEqualTo = 3,
  tolerance = 0.00001,
  error = "3 is the third element of the array",
)

Rendered example of pop 0