JavaScript String substr() Method
This method gets parts of a string, starting at the character at the defined position, and returns the specified number of characters.
Syntax:
string.substr(start, length)
Example: This example inserts one string to another by using substr() method.
// Input string
let str = 'GeeksGeeks';
// Input Substring
let subStr = 'for';
// Given index
let pos = 5;
// Insert and display output
console.log(str.substr(0, pos) + subStr + str.substr(pos));
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: