How to Get the First Character of a String
The charAt() Method
You should use the charAt() method at index 0 for selecting the first character of the string.
The substring() Method
You can also use the substring() method to get the first character:
The slice() Method
However, if prefer to use substring, the slice() version is shorter:
And to get the last character, you can simply use:
The bracket notation  Method
There is  bracket notation method of rethrieving the first element:
Unlike all above mentioned methods that return an empty string ('') for str = '' this method returns undefined:
There are 3 methods used to extract a part of a string:
- slice(start, end) - extracts a part of a string and returns the extracted part in a new string.
- substring(start, end) - similar to slice() only it cannot accept negative indexes.
- substr() - substr() is similar to slice() except the second parameter specifies the length of the extracted part.
There are 2 methods of accessing an individual character in a string:
- charAt() - returns the character at a specified index (position) in a string.
- bracket notation  - treas the string as an array-like object, where each individual character corresponds to a numerical index.