2

I'm comparing with the two arrays and if one of the array of the element matches with the other array of the element it should return the true

var data1 = ["ram","krishna"]
var data2 = ["", "ram"]
const isInArray = dat1.includes(data2)  

I used the some but i'm getting the value of ["ram"]

sonam
  • 105
  • 8
  • _"I used the `some` but i'm getting the value of `["ram"]`"_ - `.some()` returns a boolean, hence this is not possible. – Andreas Jan 04 '21 at 11:54
  • See: https://stackoverflow.com/questions/7837456/how-to-compare-arrays-in-javascript – Patrick Jan 04 '21 at 11:59

2 Answers2

2

Use filter and includes and then check the length.

var data1 = ["ram","krishna"]
var data2 = ["", "ram"]
const isInArray = data1.filter(value => data2.includes(value)).length ? true : false;
console.log(isInArray);
Lundstromski
  • 1,197
  • 2
  • 8
  • 17
1

var data1 = ["ram","krishna"]
var data2 = ["", "ram"]
const isInArray = data1.some((elem) => data2.includes(elem))
console.log(isInArray)
wuerfelfreak
  • 2,363
  • 1
  • 14
  • 29