Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #rgb #hex #js
ADD COMMENT
Topic
Name
6+8 =