screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <title>Date in Array Check</title> </head> <body> <h1>Javascript Check if a Date is contained in an Array </h1> <label for="inputDate">Enter a date:</label> <input type="date" id="inputDate"> <button onclick="checkDate()">Check</button> <p id="result"></p> <script> function isDateInArray(date, array) { return array.some((item) => item.toISOString() === date.toISOString()); } function checkDate() { const inputDate = new Date(document.getElementById('inputDate').value); const array = [ new Date('2023-06-27'), new Date('2023-06-28'), new Date('2023-06-29') ]; const result = isDateInArray(inputDate, array); document.getElementById('result').innerHTML = result ? 'Date is in the array' : 'Date is not in the array'; } </script> </body> </html>