1

I have multiple arrays of string, what I'm trying to do is extract the common values in a new array.

Let's say we have :

const arr1:string[] = ['0','1','2','3','4'];
const arr2:string[] = ['0','1','2'];
const arr3:string[] = ['0','2', '5'];
const arr4:string[] = ['1','2', '3'];

The result should be :

const result:string[] = ['2'];

Because 2 is present in each array.

With two arrays I can use filter but with more than two how can I achieve that ?

An-droid
  • 6,433
  • 9
  • 48
  • 93
  • Take the smallest array and go through each element, checking whether it's present in all the other arrays. – bugs Aug 16 '18 at 09:55

0 Answers0