console.log(truncate_string("Robin Singh",4));

function truncate_string(str,pos)
{
    var temp = str.split('')
    var ar = [];
    for(var i=0 ; i<pos ; i++)
    {
        ar.push(temp[i]);
    }
    return ar.join('');
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: