slice first letter from a string js code example

Example 1: javascript delete first character in string

var oldStr ="Hello";
var newStr = oldStr.substring(1); //remove first character "ello"

Example 2: js remove first character from string

// Return a word without the first character
function newWord(str) {
	return str.replace(str[0],"");
	// or: return str.slice(1);
	// or: return str.substring(1);
}

console.log(newWord("apple"));	// "pple"   
console.log(newWord("cherry"));	// "herry"

Tags:

Java Example