Answer the question
In order to leave comments, you need to log in
How to display the required array elements when working with Date( )?
I am doing a pet project, booking calendar. It is necessary to display the 1st and last element of the array. That is, the user selects the date of arrival and the date of departure, and by clicking the "Book" button in [output] these dates (arrival and departure) are displayed. Now all dates of residence are displayed, for example, if you select from the 27th to the 29th, the output will be: 27, 28, 29, instead of the required 27th and 29th.
Code on codepen
Problematic place:
let arr = [new Date(i).toISOString().substring(0, 10)];
out.innerHTML += `${arr[0]} - ${arr[arr.length-1]}`//Почему не выовидится 1 и последнийй элемент массива?
console.log(arr[0]); //Почему не выовидится 1й элемент массива?
Answer the question
In order to leave comments, you need to log in
Print the array arr to the console - this is an array of one element. Accordingly, arr[0] and arr[arr.length - 1] refer to the same date.
You have in your code a booking start date and an end date. Why not substitute them for i?
const startDateRender = new Date(dateStart).toISOString().substring(0, 10)
const endDateRender = new Date(dateEnd).toISOString().substring(0, 10)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question