Delete First Character of a String in TypeScript
Last Updated :
28 Apr, 2025
Deleting the first character of a string in Typescript consists of removing the character at the 0th index of the string. Using various inbuilt methods, we can extract the first character of the input string and print or return only the remaining characters apart from the first character.
There are many ways to delete the first character of the string in typescript which are as follows:
Using slice() method
The slice() method extracts the part of the input string and returns the extracted part in the new string. If we remove the string's first character, it can be done by mentioning the start index from which we want to extract the string.
Syntax:
string.slice(startingindex, endingindex);
Example: In the below example, we have passed the start index as 1 in slice(1). This extracts the string except the first character.
JavaScript
let input: string = "GeeksforGeeks";
let output: string = input.slice(1);
console.log(output);
Output:
eeksforGeeks
Using substring() method
The substring() method returns the part of the given string from the start index to the end index provided as the argument.
Syntax:
str.substring(startIndex, endIndex);
Example: To demonstrate extracting the string except the first character from the string which we passed as the start index as 1 in the substring(1) method.
JavaScript
let input: string = "GeeksforGeeks";
let output: string = input.substring(1);
console.log(output);
Output:
eeksforGeeks
Using array destructuring
The array destructuring allows us to mainly extract the values from the arrays and assign them to the variables. Then, we can join the characters into the new string.
Syntax:
let [variable1, variable2, ..., variableN] = array;
Example: In the below example, the [,...rest] uses the array destructuring to skip the first character of the input string, and then using the join method for joining the remaining characters into a new string.
JavaScript
let input: string = "GeeksforGeeks";
let [, ...rest] = input;
let output: string = rest.join('');
console.log(output);
Output:
eeksforGeeks
Using replace() method
The replace() method can be used to replace the matched character with an empty string, this can be done by giving the regular expression pattern as the argument to the method.
Syntax:
str.replace(/^./, '');
Example: To demonstrate removing the first character in the input string and print the rest of the string character using the regular expression.
JavaScript
let input: string = "GeeksforGeeks";
let output: string = input.replace(/^./, '');
console.log(output);
Output:
eeksforGeeks
Similar Reads
JavaScript - Delete First Character of a String To delete the first character of a string in JavaScript, you can use several methods. Here are some of the most common onesUsing slice()The slice() method is frequently used to remove the first character by returning a new string from index 1 to the end.JavaScriptlet s1 = "GeeksforGeeks"; let s2 = s
1 min read
Iterate Over Characters of a String in TypeScript Iterating over characters of a string involves going through them one by one using loops or specific methods. This is useful for tasks like changing or analyzing the content of a string efficiently. Example:Input: string = "Hello Geeks"; Output: H e l l o G e e k sBelow listed methods can be used to
4 min read
How to Declare an Array of Strings in TypeScript ? Arrays are fundamental data structures in TypeScript, enabling developers to manage collections of elements efficiently. Below are the approaches to declare an Array of strings in TypeScript:Table of ContentSquare Brackets NotationArray ConstructorSquare Brackets NotationUsing square brackets notati
1 min read
How to Iterate Over Characters of a String in TypeScript ? In Typescript, iterating over the characters of the string can be done using various approaches. We can use loops, split() method approach to iterate over the characters. Below are the possible approaches: Table of Content Using for LoopUsing forEach() methodUsing split() methodUsing for...of LoopUs
2 min read
TypeScript String charAt() Method The String.prototype.charAt() method in TypeScript is used to return the character at the specified index of a string. The characters in the string are indexed from left to right, starting at 0.Syntax:string.charAt( index )Parameter: This method accepts a single parameter as mentioned above and desc
2 min read
TypeScript String charCodeAt() Method The String.charCodeAt() method in TypeScript returns the Unicode value of the character at a specified index in a string. It takes an integer index as a parameter and returns the corresponding Unicode value as a number.Syntaxstring.charCodeAt(index);Parameter: This method accepts a single parameter
2 min read
TypeScript String.fromCharCode() Method The fromCharCode() is an inbuilt TypeScript String method. It mainly changes Unicode code points within the Basic Multilingual Plane (BMP) into strings. Although it provides a method for dealing with characters through typing on a keyboard it has restrictions when it comes to characters, outside the
1 min read
How to remove the first character of string in PHP? Remove the very first character of a given string in PHP Examples: Input : GeeksforgeeksOutput : eeksforgeeksInput :, Hello geek!Output : Hello geek!Explanation:In PHP to remove characters from the beginning we can use ltrim but in that, we have to define what we want to remove from a string i.e. re
3 min read
JavaScript - Delete Character from JS String In JavaScript, characters can be deleted from the beginning, end, or any specific position in a string. JavaScript provides several methods to perform these operations efficiently.Delete First CharacterTo remove the first character from a string, we can use methods like slice, substring, or regular
2 min read
Reverse a String in TypeScript Reversing a string involves changing the order of its characters, so the last character becomes the first, and vice versa. In TypeScript, there are various methods to achieve this, depending on the developer's preference and the specific requirements of the task. Table of Content Using a LoopUsing A
2 min read