JavaScript – Organize an array of objects by due_date property into its own array [duplicate]

I have an array of objects that I want to organize by the due_date property and put them into their own array. In the end I would have an array of arrays and each array would have an object where the due dates match.

For example, this is the data I’m getting:

[
    {
        task: 1,
        id: 748349238042,
        due_date: "2024-05-17"
    },
    {
        task: 2,
        id: 74374329823,
        due_date: null
    },
    {
        task: 3,
        id: 4379437297132,
        due_date: "2024-05-17"
    },
    {
        task: 4,
        id: 748349238042,
        due_date: "2024-06-03"
    },
    {
        task: 5,
        id: 789329779012,
        due_date: "2024-05-17"
    },
]

and what I would like it to look like is this:

[
    [
        {
            task: 1,
            id: 748349238042,
            due_date: "2024-05-17"
        },
        {
            task: 3,
            id: 4379437297132,
            due_date: "2024-05-17"
        },
        {
            task: 5,
            id: 789329779012,
            due_date: "2024-05-17"
        },
    ],
    [
        {
            task: 4,
            id: 748349238042,
            due_date: "2024-06-03"
        },
    ],
    [
        {
            task: 2,
            id: 74374329823,
            due_date: null
        },
    ]
]

So all the “2024-05-17” dates are in their own array and so is the “2024-06-03”, and any dates that are null are in their own array as well at the end. They don’t need to be sorted in any way in their own arrays either, I just need them together in their own array.