Try
if (msg.payload && typeof msg.payload === "string")
{
msg.payload = "RLY = ON";
return msg;
}
Truthy Truthy - MDN Web Docs Glossary: Definitions of Web-related terms | MDN
typeof typeof - JavaScript | MDN
An array has length property to.
example
[{"id":"a443d98b41ad5fd3","type":"inject","z":"d1395164b4eec73e","name":"trina with length and truthy","props":[{"p":"payload"},{"p":"separater","v":"\\","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"a strina with length and truthy","payloadType":"str","x":450,"y":4740,"wires":[["3b9b60abd878fb12"]]},{"id":"3b9b60abd878fb12","type":"function","z":"d1395164b4eec73e","name":"function 153","func":"if (msg.payload && typeof msg.payload === \"string\")\n{\n msg.payload = \"RLY = ON\";\n return msg;\n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"path","module":"path"}],"x":690,"y":4760,"wires":[["1f8ae278cd39375c"]]},{"id":"99adde23cb42603b","type":"inject","z":"d1395164b4eec73e","name":"stinng no length and falsey","props":[{"p":"payload"},{"p":"separater","v":"\\","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":450,"y":4800,"wires":[["3b9b60abd878fb12"]]},{"id":"1f8ae278cd39375c","type":"debug","z":"d1395164b4eec73e","name":"debug 2470","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1010,"y":4740,"wires":[]}]
[edit] added missing example.