Beginner questions on IF expressions and wildcard usage in function node

Or using filter

[{"id":"3f53197d243846c3","type":"inject","z":"bdd7be38.d3b55","name":"With ATC","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"mac\":\"a4c1380d5c0c\",\"Temperature\":21.6,\"Humidity\":64.7,\"DewPoint\":14.7,\"Btn\":0,\"Battery\":37,\"ATC1\":\"this is the value of ATC1\",\"RSSI\":-64}","payloadType":"json","x":700,"y":140,"wires":[["853adc83d89cddaa"]]},{"id":"3586ec0a6edd8630","type":"inject","z":"bdd7be38.d3b55","name":"No ATC","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"mac\":\"a4c1380d5c0c\",\"Temperature\":21.6,\"Humidity\":64.7,\"DewPoint\":14.7,\"Btn\":0,\"Battery\":37,\"RSSI\":-64}","payloadType":"json","x":690,"y":180,"wires":[["853adc83d89cddaa"]]},{"id":"aaaaf1995c5b6682","type":"inject","z":"bdd7be38.d3b55","name":"Multiple ATC*","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"mac\":\"a4c1380d5c0c\",\"Temperature\":21.6,\"Humidity\":64.7,\"DewPoint\":14.7,\"Btn\":0,\"Battery\":37,\"ATC1\":\"this is the value of ATC1\",\"ATC2\":\"this is the value of ATC2\",\"RSSI\":-64}","payloadType":"json","x":710,"y":220,"wires":[["853adc83d89cddaa"]]},{"id":"853adc83d89cddaa","type":"function","z":"bdd7be38.d3b55","name":"filter()","func":"// get an array of all keys starting with ATC\nconst matchingKeys = Object.keys(msg.payload).filter((element) => element.startsWith(\"ATC\"))\n// send them\nmatchingKeys.forEach((element) => node.send({payload: msg.payload[element]}))","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":870,"y":200,"wires":[["68be1dc221018baa"]]},{"id":"68be1dc221018baa","type":"debug","z":"bdd7be38.d3b55","name":"debug 99","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1020,"y":160,"wires":[]}]
1 Like