how to add comma in input type number in indian currency code example

Example 1: jquery number format comma

var number = 1557564534;
document.body.innerHTML = number.toLocaleString();
// 1,557,564,534

Example 2: convert number to indian rupee format in javascript

var x=12345678;
    x=x.toString();
    var lastThree = x.substring(x.length-3);
    var otherNumbers = x.substring(0,x.length-3);
    if(otherNumbers != '')
        lastThree = ',' + lastThree;
    var res = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree;
    alert(res);