DEV Community

Discussion on: How to get the common values of an indefinite number of arrays in Javascript

Collapse
 
alfredosalzillo profile image
Alfredo Salzillo
const arrays = [
  ["ivr", "web", "wap", "add", "acd"],
  ["web", "add"],
  ["ivr", "wap", "add", "web"],
  ["ivr", "web", "add"],
];
const commons = [...new Set(arrays.flat())]
  .filter((v) => arrays.filter(v1 => v1 === v).length > 1)
Enter fullscreen mode Exit fullscreen mode