So I'm trying to take an input JSON object which contains an array of values and simply determine, in my function node, if the variable contains an array or not. It works fine if I declare the object directly inside the function node and do the check on it. But if I inject the object as JSON and convert to to an object with the JSON node, it fails the check. Printing both objects out to the debug window indicates they are identical so I'm not sure what I'm doing wrong here. Here's an example flow illustrating the problem:
[{"id":"c55f8d246ea89274","type":"inject","z":"36608fa567377833","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"anArray\":[1,2,3]}","payloadType":"json","x":150,"y":2180,"wires":[["c8a96f421a679e11"]]},{"id":"c8a96f421a679e11","type":"json","z":"36608fa567377833","name":"","property":"payload","action":"obj","pretty":false,"x":330,"y":2180,"wires":[["178e7f23207c8603"]]},{"id":"178e7f23207c8603","type":"function","z":"36608fa567377833","name":"","func":"var object1 = {\n anArray: [1, 2, 3]\n}\n\nnode.warn(object1);\nnode.warn(msg.payload);\n\nif (object1.anArray instanceof Array)\n node.warn(\"Is Array\");\nelse\n node.warn(\"Is Not Array\");\n \nif (msg.payload.anArray instanceof Array)\n node.warn(\"Is Array\");\nelse\n node.warn(\"Is Not Array\");\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":2180,"wires":[["1b83731fc29d42d4"]]},{"id":"1b83731fc29d42d4","type":"debug","z":"36608fa567377833","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":630,"y":2180,"wires":[]}]
Here's the JSON object that I'm injecting into the function node via a JSON node:
{
"anArray": [1, 2, 3]
}
And here's the code inside the function node:
var object1 = {
anArray: [1, 2, 3]
}
node.warn(object1);
node.warn(msg.payload);
if (object1.anArray instanceof Array)
node.warn("Is Array");
else
node.warn("Is Not Array");
if (msg.payload.anArray instanceof Array)
node.warn("Is Array");
else
node.warn("Is Not Array");
Any help greatly appreciated.