let str = "Front-End Web Development"
Want to remove from the first
F letter of that
slice()won't modify the original array
slice()method extracts parts of a string
let result = str.slice(1); console.log(result); /* Output: ront-End Web Development */
Remove the first character from String using Substring
substringis the most popular method.
- This method allows you to obtain the string between two indexes by taking up to two parameters.
- If you want to remove the first character, you will only need the first parameter.
- When the function is called only one parameter, you get the characters between the first index and the string's end.
const grateFul = 'We are grateful for your visit!' const newThing = grateFul.substring(1) // 1 = index of "e" console.log(newThing) // Output: "e are grateful for your visit!"
Now that you know how to remove the first character from a string, you can move the index to remove more characters.
const grateFul = 'We are grateful for your visit!' const newThing = grateFul.substring(5) console.log(newThing) // Output: "e grateful for your visit!"
You Can Read the subString Documentation
Get and remove the first character from String using Replace
charAtfunction allows you
- To find the character at the first position.
- It's similar to using grateFul.
- The only difference is the return value if the index doesn't exist.
const grateFul = 'We are grateful' const getFirst = grateFul.charAt(0) console.log(getFirst) // Output: "W" const newThing = grateFul.replace(getFirst, '') console.log(newThing) // e are grateful
You Can Read the replace Documentation