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

**URL:** <https://discourse.nodered.org/t/how-do-you-get-only-the-last-number-thats-outputted/11000>\
**Category:** General\
**Created:** [10 May 2019 14:48 UTC](https://discourse.nodered.org/t/how-do-you-get-only-the-last-number-thats-outputted/11000 "2019-05-10T14:48:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![oaltakrouri](https://avatars.discourse-cdn.com/v4/letter/o/e8c25b/32.png) [@oaltakrouri](https://discourse.nodered.org/u/oaltakrouri)\
**Post date:** [10 May 2019 14:48 UTC](https://discourse.nodered.org/t/how-do-you-get-only-the-last-number-thats-outputted/11000/1 "2019-05-10T14:48:20Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/9f3fcdbe5eb7dfd1de8fa0fa8da5c08fbc438be1.jpeg)

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [10 May 2019 15:07 UTC](https://discourse.nodered.org/t/how-do-you-get-only-the-last-number-thats-outputted/11000/2 "2019-05-10T15:07:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [10 May 2019 16:15 UTC](https://discourse.nodered.org/t/how-do-you-get-only-the-last-number-thats-outputted/11000/3 "2019-05-10T16:15:09Z")

</div>

@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".

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

```

---

<div class="post-metadata">

**Author:** ![oaltakrouri](https://avatars.discourse-cdn.com/v4/letter/o/e8c25b/32.png) [@oaltakrouri](https://discourse.nodered.org/u/oaltakrouri)\
**Post date:** [10 May 2019 16:19 UTC](https://discourse.nodered.org/t/how-do-you-get-only-the-last-number-thats-outputted/11000/4 "2019-05-10T16:19:26Z")

</div>

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

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

```

(from [here](https://stackoverflow.com/questions/9050345/selecting-last-element-in-javascript-array/35913596))  
allowed me to get the last row, and then I just used .speed again to get the speed column.
