Here's a much easier way:
const arrays = [ ["ivr", "web", "wap", "add", "acd"], ["web", "add"], ["ivr", "wap", "add", "web"], ["ivr", "web", "add"], ]; const result = arrays.reduce((carry, array) => carry.filter((element) => array.includes(element)) ); console.log(result); // ["web", "add"]
This way, it doesn't matter how many arrays you have and what their possible values are. Also, please note, that your code is partly incorrect. You are missing " for your strings.
"
Besides, you can find more tips like this here:
Amazing! Thank you so much for your tips.. Right, your solution might be better. Now I corrected my code with " for my strings
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here's a much easier way:
This way, it doesn't matter how many arrays you have and what their possible values are. Also, please note, that your code is partly incorrect. You are missing
"
for your strings.Besides, you can find more tips like this here:
14 Awesome JavaScript Array Tips You Should Know About
Kai ・ Dec 9 ・ 9 min read
Amazing! Thank you so much for your tips.. Right, your solution might be better. Now I corrected my code with " for my strings