JavaScript - Add Characters to a String Last Updated : 16 Nov, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report 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. JavaScript const s1 = "Hello"; const s2 = s1 + " World!"; console.log(s2); OutputHello World! Using concat() MethodThe concat() method returns a new string that combines the original string with the specified values. JavaScript const s1 = "Hello"; const s2 = s1.concat(" World!"); console.log(s2); OutputHello World! Using Template LiteralsWe can use Template Literals to add characters to strings by adding expressions within backticks. This approach useful when you need to add multiple characters or variables. JavaScript const s1 = "Hello"; const s2 = `${s1} World!`; console.log(s2); OutputHello World! Using slice() MethodThe slice() method is used to add characters at specific positions in a string by slicing and then recombining parts of the original string. JavaScript const s1 = "Hello"; const s2 = "Hi, ".slice(0) + s1; console.log(s2); OutputHi, Hello Using padEnd() MethodThe padEnd() method appends characters to the end of a string until it reaches a specified length. JavaScript const s1 = "Hello"; // Add characters to reach a specific length const s2 = s1.padEnd(s1.length + 7, " World!"); console.log(s2); OutputHello World! Using Array.prototype.join() MethodWe can convert the strings to array and then use join() to add characters to a string. JavaScript const s1 = "Hello"; const s2 = ["Hi", s1, "World!"].join(" "); console.log(s2); OutputHi Hello World! Using substr() MethodAlthough substr() is generally used to extract substrings, it can also be used when adding characters by splitting and recombining the original string. JavaScript const s1 = "Hello"; const s2 = s1.substr(0) + " Everyone!"; console.log(s2); OutputHello Everyone! Using substring() MethodThe substring() method can slice portions of the original string and combine them with new characters. JavaScript const s1 = "Hello"; const s2 = "Hi, " + s1.substring(0); console.log(s2); OutputHi, Hello Comment More infoAdvertise with us Next Article JavaScript - Add Characters to a String A abhish8rzd Follow Improve Article Tags : JavaScript Web Technologies javascript-string JavaScript-String-Questions 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 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 - 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 - Insert Character at a Given Position in a String These are the following approaches to insert a character at a given position: 1. Using String Concatenation with SlicingSplit the string into two partsâbefore and after the positionâand concatenate the character in between.JavaScriptlet str = "Hello GFG"; let ch = "!"; let idx = 5; let res = str.sli 1 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 Like