Sorting array of simple objects
Options
![Mr_English](https://us.v-cdn.net/6037124/user_avatars/1271230.jpg)
Mr_English
Member ✭
I'd like to sort an array of objects, by one of the object properties 'placename'. Example element of data:
[
{
Place: 760
placename: "Birmingham"
profiles_places_id: 2
}
]
I've watched two videos, but I still don't get it:
Xano - Sorting Arrays of Objects
Xano - Array Filters: Sort
I added a sort filter in the Response as per the first video, but got errors. My set-up is shown in screenshot 1 below. I think the way I am referencing the parameter to sort by is incorrect but it's not obvious how to select the 'placename' property
The second video features quite a complex data structure and requires a loop and some other stuff which seems overly complicated for what I need.
Is there a simple way to sort the array, as described above?
In the Function stack - Response section - filter - sort.[s1.jpg]
Comments
-
so you probably want to sort your var: model. You'd actually apply this filter to that variable. Your path is almost always just going to be the name of the path (not variable) but text. var: model.placename is going to be the values of that field. You likely want it to look more like this:
[CleanShot 2022-08-12 at 14.03.25.png][CleanShot 2022-08-12 at 14.03.34.png]
Also, keep in mind if you are grabbing var: model from a query all records, there is already a sort functionality built in. Just go to the output tab and click on the edit icon next to return to enable sorting. -
- many thanks. This worked:[image.png]
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback