I have an array
var hex_to_dec = {
'0' : 0,
'1' : 1,
'2' : 2,
'3' : 3,
'4' : 4,
'5' : 5,
'6' : 6,
'7' : 7,
'8' : 8,
'9' : 9,
'A' : 10,
'B' : 11,
'c' : 12,
'D' : 13,
'E' : 14,
'F' : 15
};
and a function
function get_dec_from_hex(key){//if key=A
console.log(hex_to_dec["A"]);//works
return hex_to_dec[key];//doesnt work
}
i am trying to get the value when the key is a letter and it doesnt work… but when the key is a number i can get the value without getting “undefined” output
You don’t have to maintain that list of conversion’s yourself,
parseIntwill get you there easier.try this in your console:
From https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/parseInt