How to use String concat() Method In Javascript
The concat() method concatenates the string arguments to the calling string and returns a new string.
Syntax:
string.concat(string2, string3, ..., stringN)
Example: This example demonstrates how to insert one string into another using the concat() method by breaking the main string into two parts and then concatenating them with the substring in between.
// Input string
let str = 'GeeksGeeks';
// Input Substring
let subStr = 'for';
// Index to add substring
let pos = 5;
// Using concat() to insert the substring
let result = str.slice(0, pos).concat(subStr, str.slice(pos));
console.log(result);
Output
w3wiki
JavaScript Insert a string at position X of another string
Given two strings, the task is to insert one string in another at a specified position using JavaScript. We’re going to discuss a few methods, these are: