Saturday, August 30, 2025
HomeLanguagesJavascriptJavaScript | WebAPI | File | File.name Property

JavaScript | WebAPI | File | File.name Property

The File.name property is an inbuilt function of File WebAPI which gives the name of the file represented by a file object. The path of file is excluded from this property for security reasons.

Syntax:

var name = file.name;

Return Value: It returns a string, containing the name of the file without path.

Example:




<!DOCTYPE html>
<html>
    <head>
        <title>
            WebAPI File.name Property
        </title>
          
        <style>
            #main {
                padding: 10px;
                width: 300px;
                border: 1px solid green;
                text-align:center;
                font-size:22px;
            }
        </style>
    </head>
      
    <body>
        <div id = "main">
            <div>GeeksForGeeks</div>
            <div>file.name</div>
            <input type = "file" multiple onchange 
                = "myGeeks(this)">
        </div>
          
        <script type="text/javascript">
          
            function myGeeks(input_file) {
                var files = input_file.files;
                  
                for (var i = 0; i < files.length; i++) {
                    alert("Name of file:" + files[i].name);
                }
            }
        </script>
    </body>
</html>                    


Output:

Supported Browsers: The browser supported by WebAPI File.name property are listed below:

  • Edge 12
  • Google Chrome 13
  • Firefox 3.6
  • Opera 16
  • Internet Explorer 10
  • Safari

Reference: https://developer.mozilla.org/en-US/docs/Web/API/File/name

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32249 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6617 POSTS0 COMMENTS
Nicole Veronica
11792 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11838 POSTS0 COMMENTS
Shaida Kate Naidoo
6731 POSTS0 COMMENTS
Ted Musemwa
7013 POSTS0 COMMENTS
Thapelo Manthata
6689 POSTS0 COMMENTS
Umr Jansen
6701 POSTS0 COMMENTS