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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With