> ## Documentation Index
> Fetch the complete documentation index at: https://docs.odella.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Pop Block

> Remove and return the first or last element from an array

<Frame>
  <img src="https://mintcdn.com/odella/PGZ7enNCqh0mvwj_/block-reference/assets/pop_light.png?fit=max&auto=format&n=PGZ7enNCqh0mvwj_&q=85&s=78c2b187e647ec2a69ab02d66de80230" alt="Pop Block Screenshot" className="block dark:hidden" width="676" height="352" data-path="block-reference/assets/pop_light.png" />

  <img src="https://mintcdn.com/odella/PGZ7enNCqh0mvwj_/block-reference/assets/pop_dark.png?fit=max&auto=format&n=PGZ7enNCqh0mvwj_&q=85&s=9d4a23dfab877a6ce718de8b1e2e8737" alt="Pop Block Screenshot" className="hidden dark:block" width="660" height="422" data-path="block-reference/assets/pop_dark.png" />
</Frame>

## Overview

The Pop Block removes either the first or last element from an array and outputs both the removed element and the remaining array. By default, it pops the last element. This block is useful for processing array elements one by one in a loop.

## Key Features

* Removes and returns the first or last element of an array
* Outputs both the popped element and the remaining array
* Configurable to pop from the front or back of the array
* Useful for iterative array processing

## Inputs

<ParamField path="array" type="any[]" required>
  The array to pop from. Required. Non-array inputs will not be coerced.
</ParamField>

## Outputs

<ResponseField name="lastItem" type="any">
  The popped element. Will be labeled as "First" if popping from front, "Last" if popping from back.
</ResponseField>

<ResponseField name="restOfArray" type="any[]">
  The remaining elements of the array after popping.
</ResponseField>

## Editor Settings

<ParamField path="fromFront" type="boolean" default={false}>
  If enabled, the first element of the array will be popped instead of the last.
</ParamField>

## Example: Pop the last element from an array

1. Create an Array Block with values `["John", "Doe", "30", "Engineer"]`.
2. Add a Pop Block and connect the Array Block to its `array` input.
3. Run the flow. The `Last` output should be `"Engineer"` and the `Rest` output should be `["John", "Doe", "30"]`.

## Example: Pop the first element from an array

1. Create an Array Block with values `["John", "Doe", "30", "Engineer"]`.
2. Add a Pop Block, enable the `Pop from front` setting, and connect the Array Block to its `array` input.
3. Run the flow. The `First` output should be `"John"` and the `Rest` output should be `["Doe", "30", "Engineer"]`.

## Error Handling

The Pop Block will error if:

* The `array` input is not provided
* The input is not an array
* The input array is empty

## FAQ

<AccordionGroup>
  <Accordion title="Can I pop multiple elements from an array at once?">
    No, the Pop Block can only pop one element at a time. To remove multiple elements, use multiple Pop Blocks in sequence.
  </Accordion>

  <Accordion title="Can I use the Pop Block to pop elements from a string?">
    No, the Pop Block only works with arrays. For string manipulation, consider using a Code Block with custom JavaScript.
  </Accordion>

  <Accordion title="What if the array is empty?">
    The Pop Block will error if the array is empty. Use an If Block to check if the array is empty before popping from it.
  </Accordion>
</AccordionGroup>

## See Also

* [Array Block](/block-reference/data/array)
* [Slice Block](/block-reference/modifiers/slice)
* [Code Block](/block-reference/advanced/code)
* [Loop Controller Block](/block-reference/logic/loop-controller)
