How to use the concat() method In Javascript
The string concat() method in JavaScript is used to merge two or more strings and returns a new string that is the result of a combination of the specified string. We can also use it to add a character to the string.
NOTE: It allows you to add characters only at the end of the string.
Syntax:
initialString.concat('extraCharacter');
Example: The below code uses the concat() method to add character to a string in JavaScript.
const str1 = "GeeksforGeek";
const combStr1 = str1.concat('s');
const str2 = "JavaScrip";
const combStr2 = str2.concat('t');
console.log(combStr1, combStr2);
Output
w3wiki JavaScript
Add Characters to a String in JavaScript
In JavaScript, A string is a combination of multiple characters joined together to form a meaningful word. It can be a name or anything else. You can add an extra character to a string after it is defined to complete it or to practice adding characters.
There are several ways available in JavaScript to achieve this task as listed below:
Table of Content
- Using β+β operator
- Using the concat() method
- Using template literals
- Using slice() method
- Using substring() method
- Using substr() method
- Using Array.prototype.join() Method