JavaScript - Add a Character to the End of a String Last Updated : 20 Nov, 2024 Comments Improve Suggest changes Like Article Like Report 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. JavaScript let str = "Hello GFG"; let ch = "!"; let res = str + ch; console.log(res); OutputHello GFG! 2. Using Template LiteralsString concatenation using + or template literals is an effective way to insert a character at the end 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 = `${str}${ch}`; console.log(res); OutputHello, World!* 3. Using slice() Method The slice method to extract the original string and append the new character. JavaScript let str = "Hello GFG"; let ch = "!"; // Slices the entire string and appends the character let res = str.slice(0) + ch; console.log(res); OutputHello GFG! 4. Using Using splice() Method (Array-Based)Convert the string to an array, use splice to insert the character, and join the array back into a string. JavaScript let str = "Hello GFG"; let ch = "!"; // Convert string to array let arr = str.split(""); // Insert character at the end arr.splice(arr.length, 0, ch); // Convert array back to string let res = arr.join(""); console.log(res); OutputHello GFG! Comment More infoAdvertise with us Next Article JavaScript - Add a Character to the End of a String M meetahaloyx4 Follow Improve Article Tags : JavaScript Web Technologies javascript-string Similar Reads JavaScript - Add a Character to the Beginning of a String 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.JavaScriptlet str = "Hello, World!"; let ch = "*"; let res = ch + str; console.log(res); Output*Hello, World! 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 - 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 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 JavaScript - How to Pad a String to Get the Determined Length? Here are different ways to pad a stirng to get the specified length in JavaScript.1. Using padStart() MethodThe padStart() method can be used to pad a string with the specified characters to the specified length. It takes two parameters, the target length, and the string to be replaced with. If a nu 3 min read JavaScript String Methods JavaScript strings are the sequence of characters. They are treated as Primitive data types. In JavaScript, strings are automatically converted to string objects when using string methods on them. This process is called auto-boxing. The following are methods that we can call on strings.slice() extra 11 min read JavaScript String padStart() Method The padStart() method in JavaScript is used to pad a string with another string until it reaches the given length. The padding is applied from the left end of the string. Syntax:string.padStart(targetLength, padString)Parameters:This method accepts two parameters as mentioned above and described bel 3 min read JavaScript String padEnd() Method The padEnd() method in JavaScript is used to pad a string with another string until it reaches the given length. The padding is applied from the right end of the string.Syntax:string.padEnd( targetLength, padString );Parameters: This method accepts two parameters as mentioned above and described bel 3 min read How to create half of the string in uppercase and the other half in lowercase? The first thing that we have to keep in my mind while solving this kind of problem is that the strings are immutable i.e, If I am taking the following string var string1 = "geeksforgeeks";string1[0] = "G";console.log(string1);As strings are immutable, so we cannot change the character of the string, 9 min read Like