JavaScript - Add a Character to the Beginning of a String Last Updated : 20 Nov, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report These are the following ways to insert a character at the beginning of the given string:1. Using String ConcatenationDirectly prepend the character using the + operator or template literals. JavaScript let str = "Hello, World!"; let ch = "*"; let res = ch + str; console.log(res); Output*Hello, World! 2. Using Template LiteralsString concatenation using + or template literals is an effective way to insert a character at the beginning of a string. This method creates a new string with the desired modification without altering the original string (since strings are immutable in JavaScript). JavaScript let str = "Hello, World!"; let ch = "*"; let res = `${ch}${str}`; console.log(res); Output*Hello, World! 3. Using slice() Method Extract the original string and append the new character to it by the use of slice() method. JavaScript let str = "Hello, World!"; let ch = "*"; // Slice the entire string and prepend let res = ch + str.slice(0); console.log(res); Output*Hello, World! 4. Using Using splice() Method (Array-Based)Convert the string to an array (as strings are immutable in JavaScript), use splice to insert the character at the beginning, and join it back into a string. JavaScript let str = "Hello, World!"; let ch = "*"; // Convert string to array let arr = str.split(""); // Insert the character at index 0 arr.splice(0, 0, ch); // Convert array back to string let res = arr.join(""); console.log(res); Output*Hello, World! Comment More infoAdvertise with us Next Article JavaScript - Add a Character to the Beginning of a String M meetahaloyx4 Follow Improve Article Tags : JavaScript Web Technologies javascript-string Similar Reads JavaScript - Add a Character to the End of a String These are the following ways to insert a character at the end of the given string:1. Using ConcatenationWe can use the + operator or template literals to append the character.JavaScriptlet str = "Hello GFG"; let ch = "!"; let res = str + ch; console.log(res); OutputHello GFG! 2. Using Template Liter 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 - 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 a String at a Specific Index These are the following methods to insert a string at a specific index in JavaScript:1. Using the slice() MethodInserting a string using the slice() method involves splitting the original string into two parts: one before the insertion point and one after. The new string is then placed between these 3 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 Like