How to iterate over an Photos.app album (or a container) using Javascript?

How can I iterate over the media items of an album in Photos.app?

By copying and editing online code, I got this far:

for (const album of Application("Photos").albums()) {
    console.log("Processing album '" + album.name() + "'")
    for (var idx in album) {
        console.log(idx)
     } 
}

However, this doesn't work. I know that each album in Application("Photos").albums() is a container, but I couldn't find an example how to iterate over its content using javascript.
In other code, I have already created a javascript Map where each key is the filename(+size+ratio) and it contains lists of duplicates (all but one to be deleted).
Iterating through the albums, I want to extract the properties of the media items to check whether an item is to be deleted and if yes, replace them with the non-deleted duplicates.

Any help or pointers to examples greatly appreciated!


Solution 1:

Ok, after reading https://stackoverflow.com/questions/59471889/jxa-get-containers-of-an-element I found out, how to do it:

for (const album of Application("Photos").albums()) {
    console.log("Processing album '" + album.name() + "'")
    for (var photo of album.mediaItems()) {
        console.log(photo.filename())
    }
}

So, the correct way to do it is to iterate over the album.mediatItems() with for (var ... of ...) { ... }.