Hi
I need to count the numbers of Offline state in an array
I did find a way to use the find command, but it only takes the first one and then stops, how do I find all of them.
Next question:
how to I insert the number of offline in to a value, so in this example a value of 2
This is my output from my SQL database
[{"id":"881f149cc637aa08","type":"tab","label":"Export from MySQL","disabled":false,"info":"Export from MySQL"},{"id":"70cd0c5b25c1ba07","type":"inject","z":"881f149cc637aa08","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":260,"wires":[["e9561081af7aa794"]]},{"id":"e9561081af7aa794","type":"function","z":"881f149cc637aa08","name":"Hent Status pĂĄ Ballast 10 (9)","func":"area = \"15\" ;\n\nmsg.topic = \"SELECT a.state, a.ballast, a.area, a.created_at FROM DC46BN59 a inner join (select ballast, max(created_at) as ts from DC46BN59 group by ballast) as b on a.ballast = b.ballast and a.created_at = ts and a.area = \"+area+\"\";\nreturn msg;\n\n\n\n//[{\"state\":\"Offline\",\"ballast\":\"14\",\"area\":3,\"created_at\":\"2021-08-07T17:04:36.000Z\"},{\"state\":\"Offline\",\"ballast\":\"7\",\"area\":3,\"created_at\":\"2021-08-07T17:06:43.000Z\"},{\"state\":\"Offline\",\"ballast\":\"10\",\"area\":3,\"created_at\":\"2021-08-07T19:00:22.000Z\"}]\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":260,"wires":[["91c645589080e501"]]},{"id":"91c645589080e501","type":"mysql","z":"881f149cc637aa08","mydb":"8e1cfeb8.d5134","name":"MySQL","x":740,"y":260,"wires":[["86744ad0c14e29cc","ef1b6ea9fd8854d2"]]},{"id":"f2b623058d5b8085","type":"debug","z":"881f149cc637aa08","name":"output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1110,"y":260,"wires":[]},{"id":"86744ad0c14e29cc","type":"function","z":"881f149cc637aa08","name":"","func":"\n\nstate = \"Offline\";\n\nmsg.output = msg.payload.find((el => el.state === state))\ncount = msg.output.state; //Numbers of offline devices\nmsg.payload = count;\nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":940,"y":260,"wires":[["f2b623058d5b8085"]]},{"id":"ef1b6ea9fd8854d2","type":"debug","z":"881f149cc637aa08","name":"Raw output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":180,"wires":[]},{"id":"8e1cfeb8.d5134","type":"MySQLdatabase","name":"","host":"127.0.0.1","port":"3306","db":"nodered","tz":"","charset":"UTF8"}]
This is my output so fare