ModelWorks logoModelWorks
JSON TransformArray

pop

Remove elements from the end of an array

pop

Removes the last n elements from an array.

Options

OptionTypeRequiredDefaultDescription
nintegerNo1Number of elements to remove from the end.

Example

Input

JSON
["a", "b", "c", "d"]

Operation

JSON
{ "type": "pop", "options": { "n": 2 } }

Output

JSON
["a", "b"]

In a Circuit Step

JSON
{
  "name": "drop_last_two",
  "description": "Discard the last two events from the log",
  "function": "circuit.core.transform.json",
  "input": {
    "source": "${{ event_log }}",
    "operations": [
      { "type": "pop", "options": { "n": 2 } }
    ]
  },
  "outputs": [
    {
      "name": "trimmed_log",
      "description": "Event log with the last two entries removed",
      "value": "${{ drop_last_two.output.transformed_result }}"
    }
  ]
}

Notes & gotchas

  • Errors with pop: expected array if the input is not an array.
  • n is clamped to the array length: pop on ["a"] with n: 5 simply returns [].
  • Returns a new array; the original is not mutated.
  • Returns the remaining elements, not the removed ones (this is the JS-style "remove" semantic, not the "take and return removed" semantic).
On this page

On this page