JavaScript - Delete Character from JS String Last Updated : 21 Nov, 2024 Comments Improve Suggest changes Like Article Like Report 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 expressions.Example (Using slice): JavaScript let str = "Hello GFG"; let result = str.slice(1); // Removes the first character console.log(result); Outputello GFG You can delete the character from the beginning of the given string using many other methods, refer to this article for more Methods.Delete Last CharacterTo delete the last character from a string, methods like slice or substring are commonly used.Example (Using slice): JavaScript let str = "Hello GFG"; let result = str.slice(0, -1); // Removes the last character console.log(result); OutputHello GF You can delete the character from the end of the given string using many other methods, refer to this article for more Methods.Delete Character at a Specific PositionTo remove a character from a specific position, split the string into parts before and after the position and concatenate them.Example (Using slice): JavaScript let str = "Hello GFG"; let position = 5; let result = str.slice(0, position) + str.slice(position + 1); console.log(result); OutputHelloGFG You can delete the character from the end of the given string using many other methods, refer to this article for more Methods.Delete All Occurrence of a Character Delete the given character's occurrence from the given string and print the new string. Example (Regular Expression): JavaScript let str = "Geeks-for-Geeks"; let ch = "-"; let regex = new RegExp(ch, 'g'); let res = str.replace(regex, ''); console.log(res); OutputGeeksforGeeks You can delete all occurrence of character from the given string using many other methods, refer to this article for more Methods. Comment More infoAdvertise with us Next Article JavaScript - Delete Character from JS String M meetahaloyx4 Follow Improve Article Tags : JavaScript Web Technologies javascript-string JavaScript-String-Questions 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 JavaScript - Insert Character in JS String In JavaScript, characters can be inserted at the beginning, end, or any specific position in a string. JavaScript provides several methods to perform these operations efficiently.At the BeginningTo insert a character at the beginning of a string, you can use string concatenation or template literals 1 min read Remove a Character From String in JavaScript In JavaScript, a string is a group of characters. Strings are commonly used to store and manipulate text data in JavaScript programs, and removing certain characters is often needed for tasks like:Removing unwanted symbols or spaces.Keeping only the necessary characters.Formatting the text.Methods t 3 min read JavaScript - Delete Character at a Given Position in a String These are the following ways to Delete Character at a Given Position in a String:1. Using slice() MethodThe slice() method allows you to extract portions of a string. By slicing before and after the target position, you can omit the desired character.JavaScriptlet str = "Hello GFG"; let idx = 5; let 1 min read JavaScript - How To Get The Last Caracter of a String? Here are the various approaches to get the last character of a String using JavaScript.1. Using charAt() Method (Most Common)The charAt() method retrieves the character at a specified index in a string. To get the last character, you pass the index str.length - 1.JavaScriptconst s = "JavaScript"; co 3 min read JavaScript - How to Get Character Array from String? Here are the various methods to get character array from a string in JavaScript.1. Using String split() MethodThe split() Method is used to split the given string into an array of strings by separating it into substrings using a specified separator provided in the argument. JavaScriptlet s = "Geeksf 2 min read JavaScript - Strip All Non-Numeric Characters From String Here are the different methods to strip all non-numeric characters from the string.1. Using replace() Method (Most Common)The replace() method with a regular expression is the most popular and efficient way to strip all non-numeric characters from a string.JavaScriptconst s1 = "abc123xyz456"; const 2 min read JavaScript - Add Characters to a String Here are the various approaches to add characters to a string in JavaScriptUsing the + Operator - Most PopularThe + operator is the simplest way to add characters to a string. It concatenates one or more strings or characters without modifying the original string.JavaScriptconst s1 = "Hello"; const 2 min read JavaScript - How to Find the First and Last Character of a String? Here are the various methods to find the first and last character of a string in JavaScript.1. Using charAt() MethodThe charAt() method retrieves the character at a specified index.JavaScriptconst s = "JavaScript"; const first = s.charAt(0); const last = s.charAt(s.length - 1); console.log(first); c 2 min read JavaScript - Keep Only First N Characters in a String Here are the different methods to keep only the first N characters in a string1. Using slice() MethodThe slice() method is one of the most common and efficient ways to extract a substring from a string. We can easily keep only the first N characters by passing 0 as the start index and N as the end i 3 min read Like