Array - last value

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?

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

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

...should work (untested)

assuming the array is in msg.payload

1 Like

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

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

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

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!

@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 ```)

   code goes here 

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

See this post for more details - How to share code or flow json

1 Like

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