Home > Enterprise >  Is there an efficient way to create an image array in Javascript without having to add each individu
Is there an efficient way to create an image array in Javascript without having to add each individu

Time:09-26

is there a way in Javascript to access a file of many images without having to code each individual image separately?
I'm looking for something that pretty much accesses the whole folder with as little coding as possible, does it exist?
I've added a screenshot to illustrate. The images are in myImage folder and the array can be seen in the script but I'm wanting something more efficient. This is the code but there will be many more images to add

var URLs = [ "/myImage/2.png", "/myImage/2.png"
           , "/myImage/3.png", "/myImage/3.png"
           , "/myImage/4.png", "/myImage/4.png" ];

CodePudding user response:

You mean something like this?

https://web.dev/read-files/

CodePudding user response:

<!DOCTYPE html>
<html>
<body>

<h2>HTML Forms</h2>

<form action="/action_page.php">
  <label for="fname">Select file</label><br>
  <input type="file" id="my_input" multiple>
</form> 




<script>

  const my_file = document.getElementById('my_input');

  my_file.addEventListener('change', (event) => {

    const my_list = event.target.files;

    console.log(my_list[0].name);

  });

</script>


</body>
</html>

  • Related