javascript hex to rgb

Solutions on MaxInterview for javascript hex to rgb by the best coders in the world

showing results for - "javascript hex to rgb"
Lina
06 Mar 2017
1function rgbToHex(r, g, b) {
2  return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
3}
4
5function hexToRgb(hex) {
6  var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
7  if(result){
8      var r= parseInt(result[1], 16);
9      var g= parseInt(result[2], 16);
10      var b= parseInt(result[3], 16);
11      return r+","+g+","+b;//return 23,14,45 -> reformat if needed 
12  } 
13  return null;
14}
15console.log(rgbToHex(10, 54, 120)); //#0a3678
16console.log(hexToRgb("#0a3678"));//"10,54,120"
Christian
14 Mar 2018
1function hexToRgb(hex){
2	var result = /^#?([a-f\d]{2}])([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
3  	
4 	return result ? {
5    	r: parseInt(result[1],  16);
6      	g: parseInt(result[2],  16);
7  		b: parseInt(result[3],  16);
8    } : null;
9}
10var hex = "#0a3678";
11console.log(hexToRgb(hex).r+","+hexToRgb(hex).g+","+hexToRgb(hex).b);//10,54,120
Veronica
23 Jan 2019
1function hexToRgb(hex) {
2  // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
3  var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
4  hex = hex.replace(shorthandRegex, function(m, r, g, b) {
5    return r + r + g + g + b + b;
6  });
7
8  var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
9  return result ? [
10    parseInt(result[1], 16),
11    parseInt(result[2], 16),
12    parseInt(result[3], 16)
13  ] : null;
14}
15
16alert(hexToRgb("#0033ff").g); // "51";
17alert(hexToRgb("#03f").g); // "51";
queries leading to this page
javascript convert rgb string to hex rgb to hex in jsrgb to hex in javascriptrgb to hex conversion javascripthax to rgbhow to convert rgb to hex javascriptjavascript rgb to hex conversion 5 kyureact convert color to hexconvert hex to rgb functiontransform hexa to rgba jsrgb to color jsrgb to hexjsjavascript convert rbg to hexjs color conversionjs rgba to hexhextorgb jsconvert color hex to rgb jsjs convert rgbr to hexcalculate rgb from hex javascripthex to rgb nodejsjs rbg to hexhex to rgb jashex to rgb js hex to rgb conversion javascriptjs from hex to rgbrgbtohex javascriptjs convert rgb to hexconvert hex color to rgb jsfunction to convert rgb to hex jshow to convert hex into rgba in jshow to convert rgb to hex in javascriptjavascript how to convert hex to rgbjavascript convert rgb into hexcovert hex to rgb jsrgb to hex convertor javascriptconverting rgb value to hexcodei n jsjs hex to rgb arrayfrom hex to rgb javascriptconvert hex to rgba javascriptjavascript rgb to stringconvert hex to rgb jshow to convert hex to rgb in javascriptchange rgb to hexidecimals jsjs for converting hex to rgbjavascript hex to rbnode js hex to rgbjs color to rgbrgb string to hex converter javascriptconvert rgb value to hex javascriptcolor rgb to hex javascriptjavascript function to convert hex to rgbjavascript hex to rgbconvert hex to rgba jshow to get only the red value in the rgb with javascripthow to convert an r 2c g 2c and b to a hex code in jshex to rgb javascript functionconvert rgba to hex javascriptrgb to hex jaavscriptjs hex to rgbargb to 23 javascriptcolor rgb to hex 220x 22convert color to rgb javascriptcalculate hex from rgb jsconvert pantone to rgb 2bjavascriptconvert hex color to rgb in jsjavascript rgb to hexadecimalhow to convert hexadecimal color code to rgb in javascripttypescript convert number to hex colorcolor hexadecimal to rgb jsjs convert hex string into rgbhexadecimal to rgb jsconver rgb to hex color jsjs function that convert rgba into hexturn hex to rgb jshex color to int javascriptconvert rgb to hex javascriptjs get rgb from hexconvert rgb to hex javascript onlinesimple rgb to hex jsjs how to convert rgb to hexjs rgb to hexadecimalrgb to hex color jshexcolor to number javascriptrbg to hexcodes in jshextorgbarrayjs convert hex into rgb and hslconverting rgb to hex javascriptjs get convert color to rgbhexa to rgb javascript functiontypescript convert color to rgbtypescript rgb to hexjs rgb to 0xrgbrgb to hex jsjavascript convert rgb to hex colorhex rgb converter javascripthow to convert rgb into hex jsjavadcript hex to rgbfrom rgb to hex jsjs convert hex to rgbjs convert hex color to rgbrgb 28 29 to hex jsjavascript rgb to hexrgba to hex javascriptget decimal color from hex javascripthex to rgb on javascripthex to rgba convert javascripthex to rgb typescriptpass rgb to hexjsjavascript get rgb from hexhow to convert hex into rgb color in javascriptrgb to hexadecimal notation jsrgba to hex javacsriptget hex to rgb javascriptrgb to hex color javascriptconvert rgb color object into number jsconver rgba to hexa by javascriptjs hex to hsl and rgbhexcolor to rgbjavascriptrgbtohex functionhex code to rgb javascriptconvert rgb string to hex javascriptjavascript function to convert rgb to hexjavascript function rgb to hexjavascript convert rgb to hexadecimalhex to rgb string in jsrgb color to hex javascriptjavascript hex code to rgbjs rgb to hexhex to rgb in javascriptjavascript convert rgb color as hexcolor to rgb jsrgb to hex javascript codergb to string javascriptrgb decimal to hex javascripthex to rgb js functionjavascript convert hex to rgbajavascript convert number in rgbjs hexa to rgb converterhow to combine rgb to hexa javajavascript get rgb from hex numberrgb to hexadecimal javascriptjs change hex to rgbwork with rgb in javascriptjavascript rgba to hexrgb to hex conversion codewars javascriptconvert color to hex javascripthow to turn a hex color into rgb values in javascripthex to srgb hex jsconvert rgb to hexjavascript change rgb to hexhex to rgb converter javascriptconvert rgb color to hex javascriptconvert rgb 2825 2c 0 2c 0 29 string to hex javascriptconvert rgb style value to hex value 2c javascriptjs comvert rgb to hexjavascript convert rgb to hexrgb to hex converter javascriptreturn rgb int from hexrgb2hex javascriptconvert hex color code to rgb javascriptconvert 23rrggbb to 23rgb jsjs hex to rgb colorjs hex character to rgbjs hex array to rgbcolor hex to rgba javascriptchange hex to rgb jsrgb ot hex jsjavascript from rgb to hexjavascript rgb to hexahex to rgb and rgb to hex javscriptget rgba from hex javascriptrgb to hex conversion jsconvert r g b to hex javascriptjavascript convert hexadecimal to rgbhex to srgb jstransform rgb to hex javascriptjavascript to convery hex to rgbafrom rbg 28r 2cg 2cb 29 to int jsconvert rgb to hex javascriptpacrgb string to hex in javascriptcolor hex to rgb jsconvertir color hx a rgb en javascriptjavascript hex to rgbajshex to rgbcolor to hex jsconvert hex string to rgb javascripthex color to rgb javascripthow to convert color to rgb with javascriptchange color of an integer javascriptjs rgb from hexconvert regb to hex angularconvert rgh to hex jshow to convert rgb to hexadecimal in javascripthex to rgba jsjs get color with bit formathex string to rgb javascriptconvert rgb to hex jsjavascript convert hex to rgbjavascript convert hex code to htmlconvert rgb to hex in javascripthex to rgbjs rgb to hexhextorgb typescriptger rgb equivalent to string color javsctipshex code to rgba javascriptrgb to hsl javascriptjavascript rbg to hexfrom hex to rgbconvert hex to rgb javascrithexstring to rgb array jshow to convert rgba to hex in javascriptjs color rgb to hefunction hex to rgb stack overflowhow to convert hex to rgb javascriptrgb para hexadecimal jsrgb to hex conversion function in javascriptjs hex to rgb converterjavascript convert color string to rgbconvert hex to rgb javascript functionconvert rgb to hex code in javascriptcolor rgb to hex jsconvert rgb hex to rgb javascriptget hex code from rgb jqueryrgb to hex and back javascripthow to convert rgb to hexrgb hex converter javascriptrgb to hex javascripthow to change rgb to hex javascriptparse hex into color jsjavascript convert a hex string to rgbconvert hex to rgb es6convert rgba to hex in javascriptjs hex to rgba converterjavascript rgb to hecjs convert color hex code to rgbjs to rb converterjavascript convert color from hex to rgbcovnert hex to rbg with javascriptrget rgba to hex javascriptjava script rgb to hexhex to rgb functionjs hexa to rgbtransform rgb to hex jstransform hex to rgba jscovert rgb to hex jsconvert rgba to hex in jsconvert rgb to hex javascript functionhex to rgb convert javascriptrgb to hex javascript algorithmjavascript hrx to rgbhow to convert 8 digit hex to rgb in javascriptjs convert hexcolor to rgbconvert hexa to rgb javascriptnodejs hex to rgbconvert rgb to hexadecimal javascriptde hexadecimal a rgb jshex to rgb color converter javascriptrgba to hex converter javascriptjs convert code to hexhow to convert rgb colors to hexadecimal with javascript3 rgb numbers to hex node jscolor convert rgb to hex 220x 22convert hex color to rgb in javascriptrgba to hex jsjavascript hextorgbconvert rgb to hex color javascriptjs return rgb value from rangejavascript rgb to exadecimalergb to hexjavascript convert number in color to rgbvariable color rgb to hex javascriptif i set hex color by java it converted to rgb automatically why 3fchange hex to rgb javascripthexa to rgb jscss rgb to hex jshextorgb js not foundrgb to hex function javascriptrgba to hexhex javascriptone color rgb to hex jsjs rgb to hex why 16js hex color to rgbis there a function to convert rgb to hex javascriptconvert hex to rgbjavascript color conversionparse brazilian color to hexadecimal javascriptfunction rgb to hexajs hex to rgbconvert hex to rgb javascriptconvert hex color to rgb javascripthow to convert hex to rgb in reacttransform hex to rgb jsconvert rgb to hsl javascripthex to rgba javascriptrgb hex converter javascript from htmlhex to rgb javascriptconvert rgb color value to number javascriptjavascript hex inverterfunction from hex to rgb reactcolor input convert to rgb javascriptfunction to convert color rgbjs rgb to hex colorjavascript hex color to rgbjavascript rpg to hexjavascript rgb to hex codeget rgb from hex javascriptjavascript convert rgb string color to hexmapping from decimal to hex javascript colorconvert rbg a to hex jsrgb to hex conversion javascript codewarsfrom hexadecimal to color jsrgb to decimal code javscriptjs convert rgb to hexadecimalrgb to hexjavascriptrgb channels to hex jsrgb to hex conversion javascriptfrom rgb to hex javascript 27hextorgb 27 is not definedfunction hextorgb stackoverflowhow to convert rgb to hexadecimal in javascrptjavascript color string to rgbconvert hex code to rgb javascripthexacimal color to rgb functionjs convert hex to rgbaconvert color to rgb jsblue to hex jsconvert from hex to rgb jscalculate rgb to hex jsget color in hex format jshow to change a hex code into rgb in javascripthex characters to rgb jsrgba to hex in jsconvert hex color to rgb javascript and returns its an arryconvert hex color to rgba javascriptjs style rgb to hexjs add white to hexhex to rgb angularconvert hash color to rgb with javascriptconvert rgba to hex javascript onlineget rgb from hex jshex number to rgb jstypescript hex to rgbjs change from hex to rgb hsl functionjavascript hex to rgb