explanation for a Javascript constant with no name

Viewed 30

I am learning angular and I came across to this function that converts a date to a desired format :

export function formatDateFormDate(date: Date){
    date = new Date(date);
    const format = new Intl.DateTimeFormat('en',{
        year: 'numeric',
        month: '2-digit',
        day: '2-digit'
    });
    const [
        {value: month},
        {value : day},
        {value: year}
    ] = format.formatToParts(date);
    return `${year}-${month}-${day}`;
}

the section :

const [
        {value: month},
        {value : day},
        {value: year}
    ] = format.formatToParts(date);

I don't understand, what is this array of objects

const []

without any name?

And how does the fromatToParts function give each variable the right value?

I know what formatToParts does but I don't know how the month, day and year are getting their values from the formatToParts function.

0 Answers
Related