All good! There are two arrays of different lengths:

var a= ['Весна','Зима','Лето','Осень'] var b=['Добро','Зима','Собака'] 

How to compare arrays and output matching values ​​(in this case, Зима ) to the third array?

`

  • This can be done by iterating through the arrays, if the arrays are not sorted. If the arrays are sorted, then one array will have to be iterated sequentially, and a binary search will be performed in the second array. - Vlad from Moscow
  • And correct the title: "Find the same values ​​in array" Or it is better to use the word "matching" - Vlad from Moscow

1 answer 1

 var a = ['Весна','Зима','Лето','Осень'], b = ['Добро','Зима','Собака']; var array3 = a.filter(function(obj) { return b.indexOf(obj) >= 0; }); console.log(array3); 

  • one
    Thank you so much! Searched the whole Google did not find anything ... - Alexander