Find elements in two JavaScript arrays
P粉242126786
P粉242126786 2023-09-11 19:44:46
0
1
478

<script>
var array1 = ['2023-04-05','2023-04-06','2023-04-07'];    //array1
var array2 = ['2023-04-07'];    //array2
found1 = array1.find((val, index) => {    //在array1中查找日期
    return array2.includes(val);
});
$('.show').html(found1);
</script>

The result is 2023-04-07. How to get results similar to 2023-04-05, 2023-04-06

P粉242126786
P粉242126786

reply all(1)
P粉477369269

You can use Array#filter to get all elements in the first array that are not in the second array.

let array1 = ['2023-04-05','2023-04-06','2023-04-07'];
let array2 = ['2023-04-07'];
let res = array1.filter(x => !array2.includes(x));
console.log(res);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template