Array filter not working

I have this node red test setup where I want to filter an array of objects with another array. The problem is, the test setup returns an unfiltered copy of the original array.

could anyone tell me where I go wrong?

the input array payload is an array of elements:
msg.payload = [{"altname":"melon"},{"altname":"cherry"},{"altname":"banana"}]

the filter array exclude has 2 elements:
msg.exclude = [["melon"],["banana"]]

the function node is:

msg.payload = msg.payload.filter(el => !msg.exclude.includes(el.altname));
node.warn(msg.payload);
return msg;

I expect the output array to have only 1 element:
[{"altname":"cherry"}]

my setup:

[{"id":"b4b2e91f.8e4368","type":"inject","z":"42edc0b9.7ba91","name":"","props":[{"p":"payload"},{"p":"exclude","v":"[[\"melon\"],[\"banana\"]]","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"altname\":\"melon\"},{\"altname\":\"cherry\"},{\"altname\":\"banana\"}]","payloadType":"json","x":1650,"y":320,"wires":[["3fbdbc18.951c94"]]},{"id":"3fbdbc18.951c94","type":"function","z":"42edc0b9.7ba91","name":"cycle counter","func":"\n\nmsg.payload = msg.payload.filter(el => !msg.exclude.includes(el.altname));\n\nnode.warn(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1810,"y":320,"wires":[["ab67374c.c64458"]]},{"id":"ab67374c.c64458","type":"debug","z":"42edc0b9.7ba91","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2040,"y":300,"wires":[]}]

Don't put the strings in sub arrays.

I see!
Now the next problem: The data is provided as msg.exclude = [["melon"],["banana"]]
how would turn this to: msg.exclude = ["melon","banana"]?

Look at array map function to convert it

const a2 = a1.map(e=>e[0]); 

Also please don't cross post the same question to here and Stack Overflow

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.