The substring method is a built-in method of the String object that grabs a part of a string from the start and end indices that you specified as its arguments.
Keep in mind that the end index is excluded from the result, so you need to select the next index of the character you want to include in the substring. For example, you can extract "ors" from "Horse" with the following code:.
A string index starts at 0 so the letter "o" from "Horse" will have an index of 1. The letter "s" from "Horse" has an index value of 3 , so you need to put 4 as the second parameter of the substring method.
When you omit the second parameter, the method will return the rest of the string without cutting it:. As File inherits from Blob , File objects have the same properties, plus:. The input may select multiple files, so input. Here we have only one file, so we just take input. FileReader is an object with the sole purpose of reading data from Blob and hence File too objects.
As mentioned in the chapter Blob , FileReader can read not just files, but any blobs. They do not affect the page. PS: If you found this content valuable and want to thank me? Subscribe to our newsletter. Related Other Article. Subscribe to our newsletter Get the latest and greatest from Codepedia delivered straight to your inbox.
Last Updated : 09 Aug, To get file extensions using JavaScript, there are so many ways. The most useful ones are: split and pop method substring and lastIndexOf method match method with regular expression Above methods are described below one by one with the proper example.
Using split and pop method: The full filename is first obtained by selecting the file input and getting its value property. Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof.
But before you tackle the big projects, we suggest you start by learning the basics. Now at it's lowest price ever! Next How to convert string to camel case in JavaScript?
0コメント