get char from string js code example

Example 1: javascript get character from string

// (ES6 / ES2015)+ way of doing it
const str = "Hello World!";
const chars = [...str];

// Pre-ES2015 way of doing it
var chars2 = str.split("");

Example 2: find char in string javascript

var str = "Hello world, welcome to the universe.";

var n = str.indexOf("e");

Example 3: javascript get first character of string

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

Example 4: cut string from string javascript

var ret = "data-123".replace('data-','');
console.log(ret);   //prints: 123

Tags:

Java Example