Sorting array of simple objects

Options

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

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
     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. 
  • Mr_English
    Options
      - many thanks.  This worked:[image.png]