Skip to content

Instantly share code, notes, and snippets.

@mio-U-M
Last active August 24, 2020 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mio-U-M/8f0182994a3409962c8ed05be43000d1 to your computer and use it in GitHub Desktop.
Save mio-U-M/8f0182994a3409962c8ed05be43000d1 to your computer and use it in GitHub Desktop.
Color code exchange. Return rgb value as array.
function hexToRgb(color) {
// remove # if exist
const replacedColor = color.replace(/#/g, "");
return [
parseInt(replacedColor.substr(0, 2), 16),
parseInt(replacedColor.substr(2, 2), 16),
parseInt(replacedColor.substr(4, 2), 16)
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment