I am trying to filter out the key with the highest number from this object.
I have tried to do it with a split node, but it does not give the key, just the number.
Been searching the forum but nothing I found works.
Does anyone know how to do this with a quick function node so that the output will show the "key AND number" of the highest value only?
In this case the output of msg.payload would be (neutral : 0.976....)
Set up a change node to use this JSONata expression (the J: option):
payload.expressions.$spread()^(>*)[0]
I know, so readable, right? wth?!?
In human terms, it "spreads" the object fields into an array of single-field objects, then sorts them descending by value, and returns only the first one. If you have not looked at JSONata, it uses a very powerful lambda expression syntax to restructure JSON objects/arrays (similar to using XPath for XML data). It takes an hour or so to wrap your head around, but well worth knowing how to use in node-red, imo.