Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

240
Views
Convert files form input to arr and remove file

I decided to create one more validation, this time in user side (java-script).

I would like to do it in simple way. I decided to convert inputs files to the array, and then remove file.

my code

    let uploadField = document.getElementById("file"); //mój input

       uploadField.addEventListener('change', checkFileSize)

    
      
       function checkFileSize() {

           let amount_files = uploadField.files.length;
           
           let files_array = Array.from(uploadField.files);
       

           let maxsize = 3*1024*1024;

           console.log(Array.isArray(files_array));
          
           for(let i = 0; i < amount_files; i++) {

              if(files_array[i] >  maxsize) {
               files_array.splice(i, 1);
               
               
              }
              
           }
           console.log(files_array);
       }    

I think that on this line

if(files_array[i] > maxsize

I should put file size after "if" , but I don't know how to get it (i saw this property on console)

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!