0
I am entering some dates formatted in a array. When I select per day, the format needs to be "DD/MM", but I get from API "MM/DD", in this case I do the inversion after the push in the array, due to other rules.
The problem occurs only when the date is selected 02/29 until 01/03. The array, somehow, I think it gets lost and inserts twice the date "01/03".
Dice:
[
{pass_date_time: "03/01", name: "objeto 1" },
{pass_date_time: "02/29", name: "objeto 2" },
{pass_date_time: "03/01", name: "objeto 3" },
{pass_date_time: "03/01", name: "objeto 4" }
]
Code:
data.forEach(element => {
if (!Array.includes(element.pass_date_time)) {
Array.push(element.pass_date_time;
}
});
Array.sort();
The expected result: Array: ["01/03","02/29"]
Result obtained: Array: ["01/03","01/03"]
Is that in the backend? there are several ways to solve your problem but first need to know what you really want, your question was not very clear
– Teuuz1994
Sorry for not expressing myself well, this is in the frontend, where I get this "DATE" object from an API, what I need is to store the dates in the "ARRAY" in the correct order of the days of the months.
– iago soares
got I’ll put my answer I think I understand what you want to do...
– Teuuz1994
Reversed. The scope of the question cannot be modified after receiving answers, because if you do, it invalidates them. If you have another question create a new question.
– Augusto Vasques