Files
30-seconds-of-code/snippets/hexcode-to-RGB.md
2017-12-15 14:36:23 +02:00

306 B

Hexcode to RGB

Use Array.slice(), Array.map() and match() to convert a hexadecimal colorcode (prefixed with #) to a string with the RGB values.

const hexToRgb = hex => `rgb(${hex.slice(1).match(/.{2}/g).map(x => parseInt(x, 16)).join()})`
// hexToRgb('#27ae60') -> 'rgb(39,174,96)'