Pure work with the string you have, you could something like this:
var color = '#FF5500';
First, extract two hexadecimal digits for each color:
var redHex = color.substring(1, 3); var greenHex = color.substring(3, 5); var blueHex = color.substring(5, 7);
Then convert them to decimal numbers:
var redDec = parseInt(redHex, 16); var greenDec = parseInt(greenHex, 16); var blueDec = parseInt(blueHex, 16);
And finally, we get your rgb() as a result:
var colorRgb = 'rgb(' + redDec + ', ' + greenDec + ', ' + blueDec + ')'; console.log( colorRgb );
And you get as output:
rgb(255, 85, 0)
source share