Sort msg.payload Arrays into sections

Hello Everyone,

Thanks in advance for everyone that helps here!

Issue: I have msg.payload1.value.values that has over 100 arrays. I am wondering how to I output the data in sections like node red does? See pic below. My end goal is to have this data display in the dashboard in blocks of 10.


You can use the counter in a for loop to jump to the next "chunck" of the array and slice it:

Example

//example payload
[{"value":1},{"value":5},{"value":3},{"value":8},{"value":11},{"value":722}]

in function node


m = msg.payload
let i,j,t,c=2; // c = chunk/split by

for (i=0,j=m.length; i<j; i+=c) {
    t = m.slice(i,i+c);
    node.send({payload:t})
}

Output

msg.payload
[{"value":1},{"value":5}]
....

Thank you bakman2,

But when I run this in the function i get an error stating length is undefined.

Please see:

array.map

also threads I've written that use the array.map method that might help you.

Populate data from database into Dropdownlist

Help with my flow: generating an email from array

I am now working on a solution for you. ...... I've become the array.map guy........lord help me

meeki007

this is awesome this is what i was looking for! Sorry i missed this how to earlier when i searched. love the ui dropdown as well that's where i was heading. But when i tested the flow i got an error saying msg.payload.map is not a function.

If you really have this line in your function

m = msg.payload

Then there is no variable named m declared and you cant ask value of the .length property from not declared thing.
To do it properly it needs to be

let m = msg.payload

even after adding let to the function, it still does not understand m.length of undefined.

But what is in the msg.payload ?
Do this in first line

node.warn('this is payload:'+msg.payload)

And see debug tab

It was an example.

Your payload is: msg.payload1.value.values

To do it properly it needs to be

You don't "need" to define variables in javascript

right I ran the function with msg.payload1.value.values and got the error.

@Navybrandon

Hang in there I'm working on helping you out right now.

It may take me an hour but I have the rest of the day off and I will not leave you hanging on this. Its become my goal to teach all my favourite method in JS

You will have to redefine the values to the values of your array ofcourse.

bakman2

meeki007

I look forward in studying with you Jedi master lol

again thank you!

So what does your function look like ?

And show the actual values in your array objects.

@meeki007 would you like me to dump the msg.payload into a log so you can import it?

@bakman2
image
image

Also note the amount of arrays will vary as well.

Exactly, that won't work.

Show your msg.payload
in text (or attachment) please not screenshots

{"_msgid":"dbce60bc.4e4f8","ip":"192.168.1.41","socketid":"WGjF2ePV6s8lOw4XAAAA","Bacnet":"532897","payload":"","payload1":{"value":{"len":644,"objectId":{"type":8,"instance":532897},"property":{"id":76,"index":4294967295},"values":[{"type":12,"value":{"type":8,"instance":532897}},{"type":12,"value":{"type":2,"instance":3001542}},{"type":12,"value":{"type":2,"instance":3001587}},{"type":12,"value":{"type":2,"instance":3001589}},{"type":12,"value":{"type":2,"instance":3001591}},{"type":12,"value":{"type":2,"instance":3001593}},{"type":12,"value":{"type":2,"instance":3001594}},{"type":12,"value":{"type":2,"instance":3001595}},{"type":12,"value":{"type":2,"instance":3001597}},{"type":12,"value":{"type":2,"instance":3001598}},{"type":12,"value":{"type":2,"instance":3001599}},{"type":12,"value":{"type":2,"instance":3001600}},{"type":12,"value":{"type":2,"instance":3001601}},{"type":12,"value":{"type":2,"instance":3001602}},{"type":12,"value":{"type":2,"instance":3001603}},{"type":12,"value":{"type":2,"instance":3001606}},{"type":12,"value":{"type":2,"instance":3001607}},{"type":12,"value":{"type":2,"instance":3001608}},{"type":12,"value":{"type":2,"instance":3001609}},{"type":12,"value":{"type":2,"instance":3001610}},{"type":12,"value":{"type":2,"instance":3001613}},{"type":12,"value":{"type":2,"instance":3001614}},{"type":12,"value":{"type":2,"instance":3001615}},{"type":12,"value":{"type":2,"instance":3001617}},{"type":12,"value":{"type":2,"instance":3001621}},{"type":12,"value":{"type":2,"instance":3001625}},{"type":12,"value":{"type":2,"instance":3001627}},{"type":12,"value":{"type":2,"instance":3001629}},{"type":12,"value":{"type":2,"instance":3001633}},{"type":12,"value":{"type":2,"instance":3002186}},{"type":12,"value":{"type":2,"instance":3002188}},{"type":12,"value":{"type":2,"instance":3002194}},{"type":12,"value":{"type":2,"instance":3002199}},{"type":12,"value":{"type":2,"instance":3002200}},{"type":12,"value":{"type":2,"instance":3002201}},{"type":12,"value":{"type":2,"instance":3002202}},{"type":12,"value":{"type":2,"instance":3002203}},{"type":12,"value":{"type":2,"instance":3002204}},{"type":12,"value":{"type":2,"instance":3002393}},{"type":12,"value":{"type":2,"instance":3002394}},{"type":12,"value":{"type":2,"instance":3002395}},{"type":12,"value":{"type":2,"instance":3002397}},{"type":12,"value":{"type":2,"instance":3002401}},{"type":12,"value":{"type":2,"instance":3002404}},{"type":12,"value":{"type":2,"instance":3002405}},{"type":12,"value":{"type":2,"instance":3002406}},{"type":12,"value":{"type":2,"instance":3002408}},{"type":12,"value":{"type":2,"instance":3002409}},{"type":12,"value":{"type":2,"instance":3002410}},{"type":12,"value":{"type":2,"instance":3002412}},{"type":12,"value":{"type":2,"instance":3002416}},{"type":12,"value":{"type":2,"instance":3002481}},{"type":12,"value":{"type":2,"instance":3002482}},{"type":12,"value":{"type":2,"instance":3002484}},{"type":12,"value":{"type":2,"instance":3002485}},{"type":12,"value":{"type":2,"instance":3002488}},{"type":12,"value":{"type":2,"instance":3002490}},{"type":12,"value":{"type":2,"instance":3002491}},{"type":12,"value":{"type":2,"instance":3002493}},{"type":12,"value":{"type":2,"instance":3003932}},{"type":12,"value":{"type":2,"instance":3003933}},{"type":12,"value":{"type":2,"instance":3003936}},{"type":12,"value":{"type":2,"instance":3003937}},{"type":12,"value":{"type":2,"instance":3003943}},{"type":12,"value":{"type":2,"instance":3003944}},{"type":12,"value":{"type":2,"instance":3003946}},{"type":12,"value":{"type":2,"instance":3003948}},{"type":12,"value":{"type":2,"instance":3003949}},{"type":12,"value":{"type":2,"instance":3003950}},{"type":12,"value":{"type":2,"instance":3004089}},{"type":12,"value":{"type":5,"instance":3002205}},{"type":12,"value":{"type":16,"instance":3001584}},{"type":12,"value":{"type":19,"instance":3001539}},{"type":12,"value":{"type":19,"instance":3001540}},{"type":12,"value":{"type":19,"instance":3001543}},{"type":12,"value":{"type":19,"instance":3001544}},{"type":12,"value":{"type":19,"instance":3001545}},{"type":12,"value":{"type":19,"instance":3001546}},{"type":12,"value":{"type":19,"instance":3001596}},{"type":12,"value":{"type":19,"instance":3001605}},{"type":12,"value":{"type":19,"instance":3001611}},{"type":12,"value":{"type":19,"instance":3001616}},{"type":12,"value":{"type":19,"instance":3001620}},{"type":12,"value":{"type":19,"instance":3001622}},{"type":12,"value":{"type":19,"instance":3001624}},{"type":12,"value":{"type":19,"instance":3001626}},{"type":12,"value":{"type":19,"instance":3001628}},{"type":12,"value":{"type":19,"instance":3001630}},{"type":12,"value":{"type":19,"instance":3001631}},{"type":12,"value":{"type":19,"instance":3001632}},{"type":12,"value":{"type":19,"instance":3002185}},{"type":12,"value":{"type":19,"instance":3002187}},{"type":12,"value":{"type":19,"instance":3002189}},{"type":12,"value":{"type":19,"instance":3002192}},{"type":12,"value":{"type":19,"instance":3002195}},{"type":12,"value":{"type":19,"instance":3002196}},{"type":12,"value":{"type":19,"instance":3002197}},{"type":12,"value":{"type":19,"instance":3002392}},{"type":12,"value":{"type":19,"instance":3002398}},{"type":12,"value":{"type":19,"instance":3002402}},{"type":12,"value":{"type":19,"instance":3002403}},{"type":12,"value":{"type":19,"instance":3002476}},{"type":12,"value":{"type":19,"instance":3002477}},{"type":12,"value":{"type":19,"instance":3002483}},{"type":12,"value":{"type":19,"instance":3002486}},{"type":12,"value":{"type":19,"instance":3002487}},{"type":12,"value":{"type":19,"instance":3002489}},{"type":12,"value":{"type":19,"instance":3003916}},{"type":12,"value":{"type":19,"instance":3003917}},{"type":12,"value":{"type":19,"instance":3003918}},{"type":12,"value":{"type":19,"instance":3003919}},{"type":12,"value":{"type":19,"instance":3003920}},{"type":12,"value":{"type":19,"instance":3003921}},{"type":12,"value":{"type":19,"instance":3003934}},{"type":12,"value":{"type":19,"instance":3003935}},{"type":12,"value":{"type":19,"instance":3003938}},{"type":12,"value":{"type":19,"instance":3003939}},{"type":12,"value":{"type":19,"instance":3003940}},{"type":12,"value":{"type":19,"instance":3003941}},{"type":12,"value":{"type":19,"instance":3003942}},{"type":12,"value":{"type":19,"instance":3003945}},{"type":12,"value":{"type":19,"instance":3003947}},{"type":12,"value":{"type":20,"instance":3000005}},{"type":12,"value":{"type":20,"instance":3001649}},{"type":12,"value":{"type":20,"instance":3001650}},{"type":12,"value":{"type":20,"instance":3002181}},{"type":12,"value":{"type":20,"instance":3002497}}]}}}