The global path should be a string
e.g.
msg.serial = [];
for (var i in msg.payload){
global.set("SWSerial[" + i + "]", msg.payload[i].serial);
msg.serial.push(global.get("SWSerial[" + i + "]"));
}
return msg;
example flow
[{"id":"984f86ea.b649c8","type":"inject","z":"30af2d3e.d94ea2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"serial\":45},{\"serial\":47},{\"serial\":48}]","payloadType":"json","x":90,"y":1320,"wires":[["705d73cd.e1255c"]]},{"id":"705d73cd.e1255c","type":"function","z":"30af2d3e.d94ea2","name":"","func":"msg.serial = [];\nfor (var i in msg.payload){\nglobal.set(\"SWSerial[\" + i + \"]\", msg.payload[i].serial);\nmsg.serial.push(global.get(\"SWSerial[\" + i + \"]\"));\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":1300,"wires":[["143dd92d.782eef"]]},{"id":"143dd92d.782eef","type":"debug","z":"30af2d3e.d94ea2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":460,"y":1320,"wires":[]}]
or if separate global vars
msg.serial = [];
for (var i in msg.payload){
global.set("SWSerial" + i, msg.payload[i].serial);
msg.serial.push(global.get("SWSerial" + i));
}
return msg;