1number = 255
2h = parseInt(number, 10).toString(16)
3// Result: "ff"
4
5// Add Padding
6h = h.padStart(6, "0")
7// Result: "0000ff"
1var rgbToHex = function (rgb) {
2 var hex = Number(rgb).toString(16);
3 if (hex.length < 2) {
4 hex = "0" + hex;
5 }
6 return hex;
7};