Loop Plotly.newPlot over divs

I currently have a script that creates/names divs according to files in a folder (below). I’m looking to create a graph for each file in that folder.


            var files = fs.readdirSync(filepath)

            var x;

            for (x of files) {

              document.write("<div id = "+x+"></div>");



I’ve found the below will create and place the first graph but I’m unable to put this into a loop so I can have each graph printed beneath each other. Would anyone know how to do this?

Plotly.newPlot(x, data, layout, {responsive:true});

Thank you in advance.