How to get hex integer from a string in JS?

hex, javascript

Solution

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));

Problem

I would like to convert this: `"#FFFFFF"` to this: `0xFFFFFF`. How is it possible without using eval? Thanks in advance,

Original source

Related problems