In the below flow, I have an array with file name. From a function node, I use regex.test to check if the name matches a format. For some unknown reason, while checking this in array.forEach, the result alternate between true and false, although the value is always the same.
In my original flow, the values are different but the result is the same. I only used the same value to emphasize the problem.
[{"id":"de9b52e1a522fb37","type":"tab","label":"Flow 3","disabled":false,"info":"","env":[]},{"id":"1067019b063d7a3d","type":"function","z":"de9b52e1a522fb37","name":"Check file name","func":"const theMatch = /\\.pp[4567]$/gi\nvar theResult = true;\nnode.warn(msg.payload)\nmsg.payload.forEach(element => {\n theResult = theMatch.test(element.originalfilename);\n node.warn(element.originalfilename);\n node.warn(theResult);\n});\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":340,"wires":[["a812dc805065ecd9"]]},{"id":"9531e84f57e9dbb4","type":"inject","z":"de9b52e1a522fb37","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"originalfilename\":\"file1.pp7\"},{\"originalfilename\":\"file1.pp7\"},{\"originalfilename\":\"file1.pp7\"},{\"originalfilename\":\"file1.pp7\"}]","payloadType":"json","x":270,"y":340,"wires":[["1067019b063d7a3d","328b48aa4ee8fb75"]]},{"id":"328b48aa4ee8fb75","type":"debug","z":"de9b52e1a522fb37","name":"injected","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":420,"y":260,"wires":[]},{"id":"a812dc805065ecd9","type":"debug","z":"de9b52e1a522fb37","name":"result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":790,"y":340,"wires":[]}]