Sort objects that contain array values?


I have an object that represents a series of prices and times - as per the screenshot below


What i need to do is loop through all of the objects and then sort them based on the price field (lowest to highest)

Any hints on the way to do this ?


1 Like

With jsonata you should be able to do something like:

payload.items.$^(price)[[0, -1]]

Alternatively, a function node can do it:

msg.payload.items.sort( (A,B) => A.price - B.price )
return msg
1 Like

thanks for the hints guys - will give it a whirl and report back


Now i know why NR is so good - if you can whip something out that quickly and easily - dropped your code into a function node chained to my previous node and BOOM - exactly what i needed - thanks Nick

Now to study up online and understand what it is doing !


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