JSFiddle - React, Tailwind, and code Playground
HTML
<input type="file" id="file" multiple /><br/>
<div id="fileSize">
</div>
JavaScript
document.querySelector('input[type="file"]').addEventListener("change", function(event) {
var fSExt = new Array('Bytes', 'KB', 'MB', 'GB');
// VALIDATE OR CHECK IF ANY FILE IS SELECTED.
if (this.files.length > 0) {
// RUN A LOOP TO CHECK EACH SELECTED FILE.
for (var i = 0; i <= this.files.length - 1; i++) {
var _size = this.files.item(i).size; // THE SIZE OF THE FILE.
j=0;
//check if file is in GB,MB,KB or Bytes
while(_size > 900)
{
_size/=1024; //divide file size
j++;
}
//get exact size
var exactSize = (Math.round(_size*100)/100)+' '+fSExt[j];
document.getElementById("fileSize").innerHTML= document.getElementById("fileSize").innerHTML + "<br/>"+i+' FILE SIZE = '+ exactSize;
}
}
});