I want a function node that looks for the value of settled in the latest array item wheregrossis equal to or larger than the number35100. And allows the message to pass through if settled equals false.
So in this example, the message would pass because the last item where gross is larger than 35100 (array item 3) has a settled value of false.
In this example however, the message would not pass because the same item has a settle value of true, even though the last item in the array has false.
Have a look at my solution using find() in your other post to find the first matching element in an array. Make sure you understand how that works (ask there for help if you can't understand it after looking at the docs for Array.find()) and then have a go at solving this problem using findLast() which is exactly the same as find() except that it finds the last matching instead of the first.
Tried this code to select the last item in the array where gross is equal to or larger than 351000. And then setting the payload to that item, (for further processing using a switch node):
If msg.payload.findLast is not a function, then msg.payload is not an array. Therefore either the data is not as you showed, or it is not in msg.payload.
Also you must always return a message, so at the end you probably want
Ah, good point. @network_potato, if you are not using nodjs 18 (run node -v to find out) then you can use msg.payload.reverse().find((ArrayEntry) => ArrayEntry.gross >= 351000);
which reverses the array and then finds the first one.
Anyway, I managed to do it by using a split node, removing the unwanted items from the array with a switch node, and then joining it back together. Then selecting the last item in the array using a JSONata expression: $$.payload[-1].sale.settled.