Answer the question
In order to leave comments, you need to log in
How to make an array of dates from an array of integers?
There is an array . It is
necessary to calculate the date from each number in it and write a new array.
var date = [-2, -5, -7, -11, -19, -20];
//-Результат
["21.04.2019 г.", "18.04.2019 г.", "16.04.2019 г.", "12.04.2019 г.", "4.04.2019 г.", "3.04.2019 г."]
var date = [-2, -5, -7, -11, -19, -20];
var dateNew =[];
for (var i = 0; i < date.length; i++) {
var d = new Date(new Date().getTime() +date[i] * 24 * 60 * 60 * 1000);
var month = new Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");
var newDate = (+d.getDate() + "." + month[d.getMonth()] + "." + d.getFullYear() + " г.");
dateNew.push(newDate)
//localStorage.dateSave = JSON.stringify(dateNew);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question