This article describes the method of JS implementing the return file size based on the number of file bytes. Share it for your reference, as follows:
function getFileSize(fileByte) { var fileSizeByte = fileByte; var fileSizeMsg = ""; if (fileSizeByte < 1048576) fileSizeMsg = (fileSizeByte / 1024) + "KB"; else if (fileSizeByte == 1048576) fileSizeMsg = "1MB"; else if (fileSizeByte > 1048576 && fileSizeByte < 1073741824) fileSizeMsg = (fileSizeByte / (1024 * 1024)) + "MB"; else if (fileSizeByte > 1048576 && fileSizeByte == 1073741824) fileSizeMsg = "1GB"; else if (fileSizeByte > 1073741824 && fileSizeByte < 1099511627776) fileSizeMsg = (fileSizeByte / (1024 * 1024 * 1024)) + "GB"; else fileSizeMsg = "File exceeds 1TB"; return fileSizeMsg;}For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript Mathematical Operation Usage", "Summary of JSON Operation Skills in JavaScript", "Summary of JavaScript Switching Special Effects and Skills", "Summary of JavaScript Search Algorithm Skills", "Summary of JavaScript Animation Special Effects and Skills", "Summary of JavaScript Errors and Debugging Skills", "Summary of JavaScript Data Structures and Algorithm Skills" and "Summary of JavaScript Traversal Algorithm and Skills"
I hope this article will be helpful to everyone's JavaScript programming.