<script>
var array1 = ['2023-04-05','2023-04-06','2023-04-07','2023-04-08']; //array1
var array2 = ['2023-04-06','2023-04-07']; //array2
found1 = array1.find((val, index) => { //find the date in array1
return array2.includes(val);
});
$('.show').html(found1);
</script>
result 2023-04-062023-04-07
how to result like this 2023-04-06, 2023-04-07
2
Answers
You can achive your results by using this
if you want a string instead, you can join the array
The simplest way is to just filter, to keep values that are in both arrays
If you find yourself with super long arrays, you can benefit from
Set
s, which offer constant time lookup for if a value is contained. For small arrays, it really doesn’t matter and you might even find the creation of theSet
making theSet
approach slower.