You will get a lot more out of Node-RED by learning JavaScript, but in the meanwhile, if you explore the capabilities of the core nodes you will find that lots of problems (like yours) can be solved without writing any code.
[{"id":"fba3439d.857828","type":"function","z":"67af0149.01c99","name":"fake mqtt data","func":"msg.payload = \"State1 = DISCHARGE\\nState2 = DISCHARGE\\nState3 = DISCHARGE\"\nmsg.topic = \"sofar/status\"\nmsg.qos = 0\nmsg.retain = false\nmsg._msgid = \"d014745cacc84574\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":290,"y":320,"wires":[["b2dd2e0e.1cf33"]]},{"id":"85183425.06efa","type":"inject","z":"67af0149.01c99","name":"start","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":320,"wires":[["fba3439d.857828"]]},{"id":"bc82f146.29b38","type":"debug","z":"67af0149.01c99","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":640,"y":380,"wires":[]},{"id":"b2dd2e0e.1cf33","type":"split","z":"67af0149.01c99","name":"split on \\n","splt":"\\n","spltType":"str","arraySplt":"1","arraySpltType":"len","stream":false,"addname":"","x":470,"y":320,"wires":[["aa8f86cd.a0486"]]},{"id":"aa8f86cd.a0486","type":"switch","z":"67af0149.01c99","name":"select State1","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"State1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":620,"y":320,"wires":[["87565481.398b3"]]},{"id":"87565481.398b3","type":"change","z":"67af0149.01c99","name":"extract value","rules":[{"t":"change","p":"payload","pt":"msg","from":"State1 = ","fromt":"str","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":380,"wires":[["bc82f146.29b38"]]}]