Files
30-seconds-of-code/snippets/RGB-to-hexadecimal.md
Angelos Chalaris bb40a7ec08 Additional snippets
2017-11-30 19:12:13 +02:00

10 lines
331 B
Markdown

## RGB to hexadecimal
Convert each value to a hexadecimal string, using `toString(16)`, then `padStart(2,'0')` to get a 2-digit hexadecimal value.
Combine values using `join('')`.
```js
var rgbToHex = (r, g, b) =>
[r.toString(16).padStart(2,'0') , g.toString(16).padStart(2,'0') , b.toString(16).padStart(2,'0')].join('');
```