xxxxxxxxxx
let str = " hello"
str = str.substring(1)
xxxxxxxxxx
let str = 'Hello';
str = str.slice(1);
console.log(str);
/*
Output: ello
*/
xxxxxxxxxx
var oldStr ="Hello";
var newStr = oldStr.substring(1); //remove first character "ello"
xxxxxxxxxx
let str = 'Hello';
str = str.substring(1);
console.log(str);
/*
Output: ello
*/
xxxxxxxxxx
// example (remove the last element in the array)
let yourArray = ["aaa", "bbb", "ccc", "ddd"];
yourArray.shift(); // yourArray = ["bbb", "ccc", "ddd"]
// syntax:
// <array-name>.shift();
xxxxxxxxxx
var s1 = "foobar";
var s2 = s1.substring(1);
alert(s2); // shows "oobar"
xxxxxxxxxx
// 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"