# Array - last value

**URL:** <https://discourse.nodered.org/t/array-last-value/85653>\
**Category:** General\
**Created:** [18 February 2024 20:26 UTC](https://discourse.nodered.org/t/array-last-value/85653 "2024-02-18T20:26:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Moach2000](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/moach2000/32/88409_2.png) [@Moach2000](https://discourse.nodered.org/u/Moach2000)\
**Post date:** [18 February 2024 20:26 UTC](https://discourse.nodered.org/t/array-last-value/85653/1 "2024-02-18T20:26:05Z")

</div>

Hi! I get some data via API (battery status) into my Node-Red.  
The data has an array - up to 99 arrays and each of this array contains 4 values [0]...[3].  
I want to get the value from the latest array [80] out of 80 or [65] out of 65 and always value "3".

How can I do this?  
Br

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [18 February 2024 20:29 UTC](https://discourse.nodered.org/t/array-last-value/85653/2 "2024-02-18T20:29:56Z")

</div>

Off the top of my head, a function node with...

```auto
msg.payload = msg.payload[msg.payload.length-1][3]
return msg

```

...should work (untested)

_assuming the array is in msg.payload_

---

<div class="post-metadata">

**Author:** ![Moach2000](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/moach2000/32/88409_2.png) [@Moach2000](https://discourse.nodered.org/u/Moach2000)\
**Post date:** [18 February 2024 20:54 UTC](https://discourse.nodered.org/t/array-last-value/85653/3 "2024-02-18T20:54:52Z")

</div>

Hi @Steve-Mcl !  
I guess, this was the solution.

Again what I did:  
Function node plus your mentioned lines:

```auto
> msg.payload = msg.payload.xx.yy[msg.payload.xx.yy.length-1][3];
return msg;

```

Remark:  
xx.yy --\> its a part of my payload/array where I get the data.

I'll check the changes during the next hours and let keep you informed!  
Thank you and all the best!  
Cheers

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [19 February 2024 16:29 UTC](https://discourse.nodered.org/t/array-last-value/85653/4 "2024-02-19T16:29:23Z")

</div>

@Moach2000 - Whenever you post code in the forum, to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [19 May 2024 16:29 UTC](https://discourse.nodered.org/t/array-last-value/85653/5 "2024-05-19T16:29:35Z")

</div>

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