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('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:

Categorized in: