ModelWorks logoModelWorks
JSON TransformArray

shift

Remove elements from the beginning of an array

shift

Removes the first n elements from an array.

Options

OptionTypeRequiredDefaultDescription
nintegerNo1Number of elements to remove from the beginning.

Example

Input

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

Operation

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

Output

JSON
["c", "d"]

In a Circuit Step

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

Notes & gotchas

  • Errors with shift: expected array if the input is not an array.
  • n is clamped to the array length, so shift on ["a"] with n: 5 returns [].
  • Returns the remaining elements, not the removed ones.
  • Use unshift to add elements at the beginning.
On this page

On this page