How do you get only the last number that's outputted?

image

So I am importing a CSV file that always adds new rows, and I want to get just one of the columns, but always from the last row. I should only have 1 number outputted.

I figured out how to get the specific column by using:

msg.payload = msg.payload.speed;
return msg;

and it works, but obviously outputs all the numbers from that column.

Please help, I've asked many peers IRL but none can figure out Node-RED especially because JS is already a mediocre language itself.

Set the CSV node to output one message containing the whole set, which will be an array, then you can select the last object in the array and the appropriate member of that object.

1 Like

@Colin, did like you said and worked like a charm !

I used this code inside the function node to extract the last element from a column named "Delta".

let pay = msg.payload.pop().Delta;
msg.payload = pay;
return msg;

Thanks for the help. By doing that and then using this:

var my_array = /* some array here */;
var last_element = my_array[my_array.length - 1];

(from here)
allowed me to get the last row, and then I just used .speed again to get the speed column.

1 Like