Sensor avarage function

Looking for solution to count avarage of ‘value’ parameter from this table:

currently have this code but it returns Nan error:

const val = Object.values(msg.payload)
function calculate(array) {
    return array.reduce((a, b) => a + b) / array.length;
}
msg.payload = calculate(val)
return msg;

msg.payload = msg.payload.reduce((a,b) => a.value  + b.value) / msg.payload.length;
return msg;

still not working i think it’s something with data (line 1)

msg.payload = msg.payload.reduce((a, b) => a + b.value, 0) / msg.payload.length;
return msg;

still NaN result, i think I need to point to calculate only ‘value’ numbers in each object …

That’s what it’s doing.

image

[{"id":"606c2a396ac809de","type":"inject","z":"91a80f99.6180e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"value\":5},{\"value\":4},{\"value\":3},{\"value\":2},{\"value\":1}]","payloadType":"json","x":202,"y":4384,"wires":[["e27336b68d363182"]]},{"id":"4d3400143c8247b0","type":"debug","z":"91a80f99.6180e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":586,"y":4384,"wires":[]},{"id":"e27336b68d363182","type":"function","z":"91a80f99.6180e","name":"","func":"msg.payload = msg.payload.reduce((a, b) => a + b.value, 0) / msg.payload.length;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":4384,"wires":[["4d3400143c8247b0"]]}]