I may return several items in my payload, and some of them may/ may not return a "CustomerName", and I want to save the CustomerName(s) if it exists in any item.
I am stuck in checking if "CustomerName" exist in each item, anyone can help?
[{"id":"607cd2e8.bc340c","type":"inject","z":"5a7c2d8d.481f94","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":420,"y":1400,"wires":[["285cc5e5.9ca98a"]]},{"id":"285cc5e5.9ca98a","type":"function","z":"5a7c2d8d.481f94","name":"data","func":"msg.payload = [{\"Items\":[],\"Count\":0,\"ScannedCount\":307,\"ConsumedCapacity\":null},{\"Items\":[{\"KeyID\":{\"S\":\"7cd7a07d-08a7-43e9-8e13-faa7a32d8f9e\"},\"CustomerName\":{\"SS\":[\"tzu_yu\"]}}],\"Count\":1,\"ScannedCount\":307,\"ConsumedCapacity\":null},{\"Items\":[],\"Count\":0,\"ScannedCount\":307,\"ConsumedCapacity\":null}];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":570,"y":1400,"wires":[["d076d9bb.eeb128","4db27d61.a121b4"]]},{"id":"d076d9bb.eeb128","type":"debug","z":"5a7c2d8d.481f94","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":770,"y":1360,"wires":[]},{"id":"4db27d61.a121b4","type":"function","z":"5a7c2d8d.481f94","name":"check CustomeName","func":"\nvar myArray = msg.payload;\n\n\n//for (var i = 0; i < myArray.length; i++){\n //var type = 0;\n if (typeof(myArray[0].Items[0].CustomerName.SS[0]) != \"undefined\"){\n msg.payload = \"undefined\";\n } else {\n msg.payload = \"not undefined\";\n }\n\n\n\n/*\nvar type = myArray[0].Items[0].CustomerName.SS[0];\n if (type === undefined){\n msg.payload = \"undefined\";\n } else {\n msg.payload = \"not undefined\";\n }\n*/\n \n/*\n if (myArray[1].Items[0].hasOwnProperty(\"CustomerName\")){\n msg.payload = \"yes\";\n } else {\n msg.payload = \"no\";\n }\n \n*/\n\n/*\n//var checktype = \"\";\nfor (var i = 0; i < myArray.length; i ++){\n //checktype = typeof msg.payload[i].Items[0].CustomerName;\n if (checktype !== \"undefined\"){\n msg.payload = msg.payload.Items[i].CustomerName.SS;\n }\n}\n*/\n\n/*\n//for (var i = 0; i < myArray.length; i ++){\n if (myArray[1].Items[0].count > 0){\n msg.payload = myArray[1].Items[0].length;\n }\n*/\n\n//payload[1].Items[0]\n\n\n\nreturn msg;\n\n//payload[1].Items[0].CustomerName.SS[0]\n//if (msg.hasOwnProperty(\"motor\"))","outputs":1,"noerr":0,"initialize":"","finalize":"","x":820,"y":1420,"wires":[["295318e9.a21178"]]},{"id":"295318e9.a21178","type":"debug","z":"5a7c2d8d.481f94","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":930,"y":1380,"wires":[]}]