Function Arrays from Database

Hello All
I am having a bit of trouble with some arrays within a function node. Currently I have a mysql database that returns the last 7 days worth of data. It returns it all within an array. See here

After it returns the array. I would like to take all wheel rotations and add it together. Simple right? yeah probably for most. I have done it in php but not node red.
Brushing up on my JS in the function I was trying to use the forEach seen below. it does not appear to like this

here is the code I have now which is def wrong, I am used to the array [0] being at the end not the middle and I don't know what to do with it. I need to itterate through it hence the foreach but I am failing obviously

var p0 = msg.payload[0].wheel_rotations ;
function test(test4)
    var test2 = test4 + test2;

Any suggestions?

I'm loving jsonata more and more
add this change node after the mysql node and see how it works

1 Like

oh myyyyyyyyyyy god that was so dang easy. I was making it 100x more complicated. I so need to learn more of this jsonata . that is EXACTLY what I need sooo easy.
I will keep this in mind for the rest of my nodes that I will be doing this to and converting some old ones. :slight_smile:

1 Like

It was also easy to do in the query SELECT Sum('wheel_rotations'), (date(now())-Interval 7(day) as diff...........etc