I would like to convert this: "#FFFFFF"
to this: 0xFFFFFF
. How is it possible without using eval?
Thanks in advance,
Strip off the "#" and use parseInt()
.
var hex = parseInt(str.replace(/^#/, ''), 16);
Then, if you want to see it in hex, you can use .toString()
:
console.log(hex.toString(16));