Array from map function

Hi, how do I get a sorted array instead of an object using ->map() or an alternative method?

'myItems' => $page->myFiles()->toFiles()->map(fn ($myItem) => [
    'filename' => $myItem->filename()
]),

When I get the data through an API endpoint, I’ll get the following:

data: {
    file1 : {
        filename: 'filenameOfFile1'
    },
    file2 : {
        filename: 'filenameOfFile2'
    },
    ...
}

But lets say I sort the files in a certain way in the panel. How can I get the output of the map method to be a sorted array? I also tried to use ->toArray() and ->sorted() in multiple configurations, but didn’t get them to work either.

What I’d like to get in an ideal scenario:

data: {
    myFiles: [
        { filename: 'filenameOfFile2' },
        { filename: 'filenameOfFile1' },
        ...
    ]
}

I’d really appreciate a hint. Many thanks in advance!

I was missing ->values()

As far as I understand it, ...->map() returns an object and ...->map()->values() returns an array