charAt js code example
Example 1: javascript get last character in string
var hello = "Hello World";
var lastCharOfHello=hello.slice(-1);
Example 2: javascript get first character of string
var str="Hello Folks!"
var firstStringChar = str.charAt(0);
Example 3: javascript last character of string
var lastChar = myString[myString.length -1];
Example 4: javascript charat
myString = "Hello World!";
console.log(myString.charAt(0));
console.log(myString.charAt(5));
console.log(myString.charAt(8));
console.log(myString.charAt(23));
Example 5: string charat javascript
let str = new String("This is string");
console.log("str.charAt(0) is:" + str.charAt(0));
console.log("str.charAt(1) is:" + str.charAt(1));
console.log("str.charAt(2) is:" + str.charAt(2));
console.log("str.charAt(3) is:" + str.charAt(3));
console.log("str.charAt(4) is:" + str.charAt(4));
console.log("str.charAt(5) is:" + str.charAt(5));
output:
str.charAt(0) is:T
str.charAt(1) is:h
str.charAt(2) is:i
str.charAt(3) is:s
str.charAt(4) is:
str.charAt(5) is:i
Example 6: charAt javascript
myString = "Hello World!";
console.log(myString.charAt(0));
console.log(myString.charAt(5));
console.log(myString.charAt(8));
console.log(myString.charAt(23));