cahnge last character of string javascript code example

Example 1: javascript get last character in string

var hello = "Hello World";
var lastCharOfHello=hello.slice(-1);//d

Example 2: javascript get last n characters of string

'abc'.slice(-1); // c

Example 3: js omit last string

"somestring0".slice(0, -1)
// "somestring"

Example 4: get last letter of string javascript

// Get last n characters from string
var name = 'Shareek';
var new_str = name.substr(-5); // new_str = 'areek'

Example 5: javascript last character of string

var lastChar = myString[myString.length -1];