In my JavaScript/TypeScript application built with Angular, I am facing the challenge of merging multiple arrays and extracting the common values that appear in all arrays. For example:
arrayOne = [34, 23, 80, 93, 48]
arrayTwo = [48, 29, 10, 79, 23]
arrayThree = [23, 89, 48, 20, 63]
The desired output should be: outputArr= [23, 48]
To achieve this for two arrays, I am using a filtering method where I filter one array based on the elements present in the other array.
return this.arrayOne.filter(el => this.arrayTwo.includes(el));
However, I am now seeking an efficient way to handle a large number of arrays while still obtaining the common elements. Any suggestions or advice on how to tackle this effectively would be highly appreciated. Thank you in advance!