Getting i Elements by Id

Hi! I’m trying to figure out how to write:
const file0 = document.getElementById(“file0”)
const file1= document.getElementById(“file1”)
without writing it out 10 times.

So far my code is:

const files = [ ]

for (let i = 0; i <= 9; i++){
files[i] = “file” + i;

which helps me to make an array but it doesn’t pull the elements from the HTML

What did you do to get the HTML elements individually?

const file0 = document.getElementById("file0");

You used getElementById() because that returns the element, right? So why wouldn’t you need to do that when creating an array of elements?

I solved it and was able to get all 30 variables using just these few lines:

for (let i = 0; i <= 9; i++){
files[i] = document.getElementById(“file” + i);
outputs[i] = document.getElementById(“output” + i);
buttons[i] = document.getElementById(“customButton” + i);

so now when I write a function that needs elements of corresponding indexes, I don’t have to repeat it 10 times.