javascript last character of string code example

Example 1: javascript get last character in string

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

Example 2: javascript remove last character from string

var str = "Hello";
var newString = str.substring(0, str.length - 1); //newString = Hell

Example 3: get last word in string js

function test(words) {
    var n = words.split(" ");
    return n[n.length - 1];
}

Example 4: javascript get first character of string

var str="Hello Folks!"
var firstStringChar = str.charAt(0); //H

Example 5: how to get last string in javascript

'abc'.slice(-2);

Example 6: javascript last character of string

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

Tags:

Php Example