Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

rgb to hex javascript

// Convert RGB to Hex
function getColorFun(r, g, b) {
   return '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
}

getColorFun(178, 232, 55);
// The output here is #b2e837
Comment

rgb to hex js

const rgb2hex = (rgb) => `#${rgb.match(/^rgb((d+),s*(d+),s*(d+))$/).slice(1).map(n => parseInt(n, 10).toString(16).padStart(2, '0')).join('')}`

// Use as you wish...
console.log(rgb2hex('rgb(0,0,0)'))
console.log(rgb2hex('rgb(255, 255, 255)'))
console.log(rgb2hex('rgb(255,0,0)'))
console.log(rgb2hex('rgb(38, 170, 90)'))
 Run code snippet
Comment

convert hex code to rgb javascript

function hexToRgb(hex){
	var result = /^#?([a-fd]{2}])([a-fd]{2})([a-fd]{2})$/i.exec(hex);
  	
 	return result ? {
    	r: parseInt(result[1],  16);
      	g: parseInt(result[2],  16);
  		b: parseInt(result[3],  16);
    } : null;
}
var hex = "#0a3678";
console.log(hexToRgb(hex).r+","+hexToRgb(hex).g+","+hexToRgb(hex).b);//10,54,120
Comment

rgb to hex js

function rgb(r, g, b){
  // complete this function 
  return hexC(r)+hexC(g)+hexC(b)
}
function hexC(v){
  if(v>255){
    v=255
  }else if(v<0){
    v=0
  }
  let a=v%16;
  let b=Math.floor(v/16);
  return hmaps[b]+hmaps[a]
  }
let hmaps={
  0:'0',1:'1',2:'2',3:'3',4:'4',5:'5',6:'6',7:'7',8:'8',9:'9',10:'A',11:'B',12:'C',13:'D',14:'E',15:'F'
  }
Comment

PREVIOUS NEXT
Code Example
Javascript :: postgresql update json field key value 
Javascript :: javascript fill array 
Javascript :: naming branches git 
Javascript :: how to tell c++ a function exists before calling 
Javascript :: split a message js 
Javascript :: how to check whether a string contains a substring in typescript online 
Javascript :: How to fix CSS & JS not loading issue in cPanel laravel 
Javascript :: mongodb filter empty array 
Javascript :: jquery fade opacity 
Javascript :: node js run bat file 
Javascript :: how to return 5 records instead of 10 records in datatable in laravel 
Javascript :: class with attribute selector jquery 
Javascript :: call a function when page is loaded 
Javascript :: check if a string contains digits js 
Javascript :: js enter key event listener 
Javascript :: last element of an array javascript 
Javascript :: jquery debounce 
Javascript :: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 
Javascript :: vite install in vue 
Javascript :: firebase storage javascript delete document 
Javascript :: js import export es5 
Javascript :: get date javascript format 
Javascript :: convert a string to a number in javascript 
Javascript :: js background 
Javascript :: NextJS PWA gitignore 
Javascript :: convert array string to number 
Javascript :: vue.js function to always uppercase when the client input lowercase 
Javascript :: three js get size of object 
Javascript :: require is undefined 
Javascript :: popin localstorage once 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =