How does js determine that an item in one array contains another array?
such as the question: how does js determine an item in an array that contains another array?
if
A=[1,2,3,4,5,6];
B=[8,10,6,7,8];
how can you tell that an item in array B also exists in array A (it is best to return the sequence value of the item in B)?
or how to tell if two arrays have the same item?
use es5 as much as possible
let A=[1,2,3,4,5,6],
B=[8,10,6,7,8];
A.find(item=>B.includes(item)) //undefined
var a=[1,2,3,4,5,6];
var b=[8,10,6,7,8];
function getArrRepeat(arr1,arr2){
return arr1.filter((item,index) =>{
return arr2.includes(item)
})
}
console.log(getArrRepeat(a,b)) //6
at your request, do not use ES6, with ES5
var mix = [1,2,3,4,5,6].filter(function(item){
return [8,10,6,7,8].indexOf(item) != -1
});
console.log(mix) //
includes and indexOf can both
double for circulation