How to get hex integer from a string in JS?
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));
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));