Skip to content

Instantly share code, notes, and snippets.

@kartiknair
Created May 12, 2020 11:00
Show Gist options
  • Save kartiknair/12c29ca6cbc7facae9395e51cc335936 to your computer and use it in GitHub Desktop.
Save kartiknair/12c29ca6cbc7facae9395e51cc335936 to your computer and use it in GitHub Desktop.
const hexToRgb = (hexString) => {
if (hexString.startsWith("#")) hexString = hexString.substr(1);
return [
parseInt(hexString.substring(0, 2), 16),
parseInt(hexString.substring(2, 4), 16),
parseInt(hexString.substring(4, 6), 16),
];
};
console.log(hexToRgb("#ffffff")); // [255, 255, 255]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment