In JavaScript, you can use the ‘File’ object to get the name, size, and type of a file. Here is an example:
// using the input element and FileReader API
const input = document.querySelector('input[type="file"]');
input.addEventListener('change', function () {
const file = this.files[0];
console.log('name:', file.name);
console.log('size:', file.size);
console.log('type:', file.type);
});
In this example, a file input element is selected and an event listener is added to it to listen for when a file is selected. When a file is selected, the ‘change’ event is fired, and the event listener calls a function that logs the name, size, and type of the first file in the ‘files’ list.
Also Read:
- What Is a Web Worker In JavaScript?
- How To Sort an Array of Strings In JavaScript?
- ECMAScript vs JavaScript
- What Is Strict Mode In JavaScript?
- Arrow Functions In JavaScript
- Difference Between Node.js and AngularJS With Example
- Difference Between == And === In JavaScript
- What Is JSON In JavaScript
- How To Go Back To Previous Page In JavaScript?
- How To Detect A Mobile Device With JavaScript?
- How To Close The Current Tab In A Browser Window Using JavaScript?
- How To Convert Input Text To Uppercase While Typing Using JavaScript?
- How To Show A Confirmation Message Before Delete In JavaScript?
- How To Detect Browser or Tab Closing In JavaScript?
- How To Get Hash Value From URL Using JavaScript?
- Run JavaScript From The Command Line