# Loop Function for JSON table

**URL:** <https://discourse.nodered.org/t/loop-function-for-json-table/18116>\
**Category:** General\
**Created:** [18 November 2019 20:17 UTC](https://discourse.nodered.org/t/loop-function-for-json-table/18116 "2019-11-18T20:17:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![forrest.gates](https://avatars.discourse-cdn.com/v4/letter/f/c77e96/32.png) [@forrest.gates](https://discourse.nodered.org/u/forrest.gates)\
**Post date:** [18 November 2019 20:17 UTC](https://discourse.nodered.org/t/loop-function-for-json-table/18116/1 "2019-11-18T20:17:50Z")

</div>

Hi there,

I am a newer user of node-red, and I'm attempting to use a function that will read directly from a JSON table and spit out all the values in order so that it can be read in a line chart. However when i try to make such loop it does not seem to spit out any values at all.

var newMsg = { payload: msg.payload.length };  
var i = newMsg;

for (x = 0; x \< i; x++)  
{  
return payload[1].V;  
}

msg.payload = msg.payload[i].V  
return msg

I am curious to know if there is a better way to approach this formula or if minor tweaking is needed. Thanks in advance for the help!

---

<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:** [18 November 2019 22:05 UTC](https://discourse.nodered.org/t/loop-function-for-json-table/18116/2 "2019-11-18T22:05:55Z")

</div>

I suggest you start by reading the node red doc [Writing Functions](https://nodered.org/docs/user-guide/writing-functions). That should help to get you going.  
However if by table you actually mean that the payload coming in is an array then have a look at the Split node which will do exactly what you want I believe.
