`Sort` on undefined values not going at the end of array

default discord avatar
Blankeos
last month
4
https://localhost:3000/api/posts?sort=priority

Tried doing this with an

optional property

called

priority

. It seems to sort it properly, but only for docs with the values. The ones that don't have it

(undefined)

, don't go to the end of the array for some reason...

  • discord user avatar
    denolfe
    Payload Team
    4 weeks ago

    Where do the ones that have it

    undefined

    end up? Interspersed? Missing?

  • default discord avatar
    Blankeos
    4 weeks ago

    The

    undefined

    are on the first of the list.

  • discord user avatar
    denolfe
    Payload Team
    4 weeks ago

    So to me, an

    undefined

    value is considered lower and falsy - therefore considered

    first

    on an ascending sort.



    Can you cite any precedent for having

    undefined

    at the end of the list?



    I'm not able to turn up examples of how other frameworks handle this for comparison.

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.