Javascript String toInt(fallBack)

Description

Javascript String toInt(fallBack)

String.prototype.toInt = function (fallBack) {
    fallBack = fallBack || 0;//from  w  ww .  j av  a 2 s  .c  o  m
    var str = this;
    if(!str){
        return fallBack;
    }
    var strAsInt = parseInt(str);
    if(isNaN(strAsInt)){
        return fallBack;
    } else {
        return strAsInt;
    }
}



PreviousNext

Related