I thought this was not an easy task, but it is becoming very difficult. See Code.
// Convert "rgb(255, 255, 255)" to (255, 255, 255) and then to Hex code var data = { color:"rgb(165,199,72)", color:"rgb(229,121,74)", color:"rgb(105,177,222)" } // rgb To Hex Conversion var componentToHex = function(c) { var hex = c.toString(16); return hex.length == 1 ? "0" + hex : hex; } var rgbHex = function(r, g, b) { return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b); } //Substring "rgb(255, 255, 255)" to "(255, 255, 255)" var subStringRGB = function(c){ var b = c.substring(4, c.length); } var stringRGBtoNumber = function(c){ var b = Number(c.split(',')); }
Throws an error, cannot read the undefined split. How to fix it?
source share