<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>
結果為2023-04-07。如何得到類似2023-04-05, 2023-04-06的結果
P粉4773692692023-09-12 14:01:47
您可以使用Array#filter
來取得第一個陣列中不在第二個陣列中的所有元素。
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);