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

# Sort Data

> Sort and organize data collections

The Sort Data block allows you to organize and arrange data in your workflow, whether it's table data or variables containing arrays. This is useful for:

* **Rearranging table data** based on specific properties
* **Sorting arrays or lists** stored in variables
* **Organizing scraped or collected data** before exporting

This block is often used in **data manipulation, automation workflows, and AI-powered sorting tasks**.

## Inputs

### ☐ Description *(Optional)*

A brief note explaining the purpose of this sorting operation.

### ☐ Data Source *(Required)*

Choose what type of data to sort:

<CardGroup cols={1}>
  <Card title="Sort Options">
    **Description:**
    Select the data source and sorting method.

    **Sources:**

        ☐ Edit Table Columns (sort table data)

        ☐ Variable (sort array/list data)

    **Features:**

        ☐ Sort by property

        ☐ Multiple sort criteria

        ☐ Ascending/Descending order
  </Card>
</CardGroup>

### ☐ Sort Properties *(Required if sorting by property)*

Define how the data should be sorted.

<Note type="success">
  **Good Examples:**

  * "price" (for product data)
  * "lastName" (for user data)
  * "date" (for timestamps)
</Note>

### ☐ Output Options *(Required)*

Choose where to store the sorted data:

<CardGroup cols={1}>
  <Card title="Output Settings">
    **Options:**

        ☐ Assign to Variable (store in new variable)

        ☐ Insert to Table (update existing table)

    **Note:** You can select both options to store results in multiple locations
  </Card>
</CardGroup>

## Use Cases

* **Sorting Data Alphabetically** → Useful for names, products, or lists
* **Arranging Numbers in Order** → Sort numerical values from smallest to largest
* **Reordering JSON or Objects** → Organize data based on specific attributes
* **Filtering & Processing Data Before Exporting** → Ensure data is well-structured before saving

## Usage Examples

<CardGroup cols={1}>
  <Card title="1. Price Sorting" icon="dollar">
    <div className="flex flex-col space-y-2">
      <div className="flex items-center gap-2 text-sm">
        <span className="px-2 py-1 bg-purple-100 rounded-md">Source</span>
        <code className="text-green-600">products</code>
      </div>

      <div className="flex items-center gap-2 text-sm">
        <span className="px-2 py-1 bg-purple-100 rounded-md">Property</span>
        <span className="font-mono bg-slate-100 px-2 py-1 rounded">price</span>
      </div>

      <div className="flex items-center gap-2 text-sm">
        <span className="px-2 py-1 bg-purple-100 rounded-md">Order</span>
        <span className="font-mono bg-slate-100 px-2 py-1 rounded">ascending</span>
      </div>

      <div className="flex items-center gap-2 text-sm">
        <span className="px-2 py-1 bg-purple-100 rounded-md">Output</span>
        <code className="text-green-600">sortedProducts</code>
      </div>
    </div>

    <Note className="mt-2">Sort products by price (lowest to highest)</Note>
  </Card>

  <Card title="2. Name Sorting" icon="user">
    <div className="flex flex-col space-y-2">
      <div className="flex items-center gap-2 text-sm">
        <span className="px-2 py-1 bg-purple-100 rounded-md">Source</span>
        <code className="text-green-600">userList</code>
      </div>

      <div className="flex items-center gap-2 text-sm">
        <span className="px-2 py-1 bg-purple-100 rounded-md">Property</span>
        <span className="font-mono bg-slate-100 px-2 py-1 rounded">lastName</span>
      </div>

      <div className="flex items-center gap-2 text-sm">
        <span className="px-2 py-1 bg-purple-100 rounded-md">Order</span>
        <span className="font-mono bg-slate-100 px-2 py-1 rounded">ascending</span>
      </div>

      <div className="flex items-center gap-2 text-sm">
        <span className="px-2 py-1 bg-purple-100 rounded-md">Table</span>
        <code className="text-green-600">Users</code>
      </div>
    </div>

    <Note className="mt-2">Sort users alphabetically by last name</Note>
  </Card>

  <Card title="3. Date Sorting" icon="calendar">
    <div className="flex flex-col space-y-2">
      <div className="flex items-center gap-2 text-sm">
        <span className="px-2 py-1 bg-purple-100 rounded-md">Source</span>
        <code className="text-green-600">events</code>
      </div>

      <div className="flex items-center gap-2 text-sm">
        <span className="px-2 py-1 bg-purple-100 rounded-md">Property</span>
        <span className="font-mono bg-slate-100 px-2 py-1 rounded">date</span>
      </div>

      <div className="flex items-center gap-2 text-sm">
        <span className="px-2 py-1 bg-purple-100 rounded-md">Order</span>
        <span className="font-mono bg-slate-100 px-2 py-1 rounded">descending</span>
      </div>

      <div className="flex items-center gap-2 text-sm">
        <span className="px-2 py-1 bg-purple-100 rounded-md">Output</span>
        <code className="text-green-600">sortedEvents</code>
      </div>
    </div>

    <Note className="mt-2">Sort events by date (newest first)</Note>
  </Card>
</CardGroup>

## Notes

<Warning>
  * Ensure data types match before sorting
  * Check for missing or null values
  * Consider performance with large datasets
  * Verify sort order meets requirements
</Warning>
