# How to sort array in ascending order?

**URL:** <https://community.n8n.io/t/how-to-sort-array-in-ascending-order/111960>\
**Category:** Questions\
**Created:** [May 7, 2025, 6:05am UTC](https://community.n8n.io/t/how-to-sort-array-in-ascending-order/111960 "2025-05-07T06:05:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ruriko](https://avatars.discourse-cdn.com/v4/letter/r/e68b1a/32.png) [@Ruriko](https://community.n8n.io/u/Ruriko)\
**Post date:** [May 7, 2025, 6:05am UTC](https://community.n8n.io/t/how-to-sort-array-in-ascending-order/111960/1 "2025-05-07T06:05:57Z")

</div>

## Describe the problem/error/question

I have an array and I want to sort the list in ascending order. How can I do this? I want the field “filename” to be in ascending order. All other fields should follow the order if “filename” is sorted

## What is the error message (if any)?

## Please share your workflow

## Share the output returned by the last node

## Information on your n8n setup

- \*\*n8n version:1.89.2
- \*\*Database (default: SQLite):default
- \*\*n8n EXECUTIONS\_PROCESS setting (default: own, main):default
- \*\*Running n8n via (Docker, npm, n8n cloud, desktop app):npm
- \*\*Operating system:Windows Server 2022

---

<div class="post-metadata">

**Author:** ![Gallo\_AIA](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/gallo_aia/32/69059_2.png) [@Gallo\_AIA](https://community.n8n.io/u/Gallo_AIA)\
**Post date:** [May 7, 2025, 6:50am UTC](https://community.n8n.io/t/how-to-sort-array-in-ascending-order/111960/2 "2025-05-07T06:50:12Z")

</div>

Ehy!  
Does the sort node you entered in the workflow not work?

Alternatively, do not use a simple sort but a via code.

---

<div class="post-metadata">

**Author:** ![mohamed3nan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mohamed3nan/32/188347_2.png) [@mohamed3nan](https://community.n8n.io/u/mohamed3nan)\
**Post date:** [May 7, 2025, 6:52am UTC](https://community.n8n.io/t/how-to-sort-array-in-ascending-order/111960/3 "2025-05-07T06:52:43Z")

</div>

Hi @Ruriko

This is a nice one to be honest 😃

I’ve attached a working example for your use case, Please give it a try and let me know how it goes!

The key is to split the arrays into individual items so you can use the **Sort** node. To keep the other fields in sync, concatenate them (`link, filename, directory`) before splitting; then sort the combined items and finally aggregate them back into the original array structure, now sorted.

I hope the example explains it more clearly:

* * *

> **⚡**
>
> If this answers your question, Kindly mark the reply as the solution ✅ so others with the same issue can find it easily 🙏🏻

---

<div class="post-metadata">

**Author:** ![darrell\_tw](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/darrell_tw/32/52180_2.png) [@darrell\_tw](https://community.n8n.io/u/darrell_tw)\
**Post date:** [May 7, 2025, 8:13am UTC](https://community.n8n.io/t/how-to-sort-array-in-ascending-order/111960/4 "2025-05-07T08:13:48Z")

</div>

Another try for sorting in `expression`  
But this will only sort `filename` only.

---

<div class="post-metadata">

**Author:** ![mohamed3nan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mohamed3nan/32/188347_2.png) [@mohamed3nan](https://community.n8n.io/u/mohamed3nan)\
**Post date:** [May 7, 2025, 8:21am UTC](https://community.n8n.io/t/how-to-sort-array-in-ascending-order/111960/5 "2025-05-07T08:21:33Z")

</div>

@darrell_tw There is a tricky part: syncing the other fields after sorting by `filename`,  
Your solution only sorts `filename`, without syncing the other fields…

---

<div class="post-metadata">

**Author:** ![darrell\_tw](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/darrell_tw/32/52180_2.png) [@darrell\_tw](https://community.n8n.io/u/darrell_tw)\
**Post date:** [May 7, 2025, 9:02am UTC](https://community.n8n.io/t/how-to-sort-array-in-ascending-order/111960/6 "2025-05-07T09:02:27Z")

</div>

Yeah didn’t see the requirement. I thought it’s only sorting filename.

Will change the context!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [May 14, 2025, 9:03am UTC](https://community.n8n.io/t/how-to-sort-array-in-ascending-order/111960/7 "2025-05-14T09:03:00Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
