var target = '2ac'; var result = 0; var base = 10; var arr = [ '0','1','2','3','4','5','6','7','8', '9','a','b','c','d','e','f','g','h', 'i','j','k','l','m','n','o','p','q', 'r','s','t','u','v' ]; var len = target.length; for(var i = 0; i < len; i++){ if(/\d/.test(target[i])){ result += Number(target[i]) * Math.pow(base,len - 1 - i); }else{ result += arr.indexOf(target[i]) * Math.pow(base,len - 1 - i); } } console.log(result);