javascript – File uploads with image previews using Array and readAsDataURL

 let count = 0

 function previewFiles(input) {
   const preview = document.getElementById('preview')
   const {
     files
   } = input

   Array.from(files).forEach(file => {
     const reader = new FileReader()

     reader.onload = e => {
       const div = document.createElement('div')
       const img = document.createElement('img')
       const button = document.createElement('button')

       img.src = e.target.result
       img.width = 200
       img.height = 200
       img.alt = `file-${++count}`

       button.textContent = "Delete"
       button.addEventListener('click', () => {
         preview.removeChild(div)
       })

       div.appendChild(img)
       div.appendChild(button)

       preview.appendChild(div)
     }

     reader.readAsDataURL(file)
   })
 }
    <input type="file" multiple onchange="previewFiles(this);" />
    <div id="preview"></div>