JavaScript Program to Insert a String at Specific Position

Write a JavaScript program to insert a string at specific position.



Source Code
<html>
<head>
    <title>Insert a string at specific position</title>
</head>
<body>
<script>
    var str1 = "Hello World!";
    var str2 = "welcome to the ";
    var index = 6;
    var str3 = insertAt(index, str1, str2);
    document.writeln(str3);

    function insertAt(pos, s1, s2) 
    {
        var a = s1.substring(0, index);
        var b = s1.substring(index, s1.length);
        var c = a.concat(s2).concat(b);
        return c;    
    }
</script>
</body>
</html>
Output