javascript get last character of string
var str = "Hello";
var newString = str.substring(0, str.length - 1); //newString = Hell
javascript get last character of string
var str = "Hello";
var newString = str.substring(0, str.length - 1); //newString = Hell
JavaScript the last word of a string
// Get the last word of a string.
let str = "What I hate most in the world is fanaticism.";
// 1) The slice() method: without Considering the punctuation marks
str.slice(str.lastIndexOf(' ')); // => 'fanaticism.'
// 2) the spit() method():
let arr = str.split(' ');
arr[arr.length - 1]; // => 'fanaticism.'
// Considering the punctuation marks at the end of the string
str.match(/\b(\w+)\W*$/)[1]; // => 'fanaticism'
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us