convert to hexadecimal javascript code example
Example 1: js number to hex
number = 255
h = parseInt(number, 10).toString(16)
// Result: "ff"
// Add Padding
h = h.padStart(6, "0")
// Result: "0000ff"
Example 2: to hex javascript
var rgbToHex = function (rgb) {
var hex = Number(rgb).toString(16);
if (hex.length < 2) {
hex = "0" + hex;
}
return hex;
};