An elegant and short alternative, is the String.prototype.slice
method.
Just by:
str.slice(-1);
A negative start index slices the string from length+index
, to length
, being index -1
, the last character is extracted:
"abc".slice(-1); // "c";
More Related Contents:
- I want to print odd numbers using javascript [closed]
- Explain what the function does [closed]
- Most efficient method to groupby on an array of objects
- How to force JS to do math instead of putting two strings together [duplicate]
- Detect Click into Iframe using JavaScript
- How to customize object equality for JavaScript Set
- Sorting a JavaScript object by property name
- Using an HTML button to call a JavaScript function
- react router v6 navigate outside of components
- JS : Convert Array of Strings to Array of Objects
- How to make ng-bind-html compile angularjs code
- Is there a built-in way to loop through the properties of an object?
- How to remove emoji code using javascript?
- Google Chrome “window.open” workaround?
- Determine distance from the top of a div to top of window with javascript
- How to handle “Unchecked runtime.lastError: The message port closed before a response was received”?
- Download Blob file from Website inside Android WebViewClient
- Ellipsis in the middle of a text (Mac style)
- Implementing Mozilla’s toSource() method in Internet Explorer
- How to open maximized window with Javascript?
- fancybox bug with trigger click
- How to use FormData in react-native?
- If Browser is Internet Explorer: run an alternative script instead
- Not possible to set Filter value using data binding?
- Declare a class property outside of a class method
- Accessing a DOM object defined in an external SVG file
- How to get an element’s padding value using JavaScript?
- Connecting to remote SSH server (via Node.js/html5 console)
- iOS 11 getUserMedia not working?
- Show values on top of bars in a barChart