hexstring to rgb array js
JavaScript
function rgbToHex(r, g, b) {
return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
}
function hexToRgb(hex) {
var result = /^#?([a-fd]{2})([a-fd]{2})([a-fd]{2})$/i.exec(hex);
if(result){
var r= parseInt(result[1], 16);
var g= parseInt(result[2], 16);
var b= parseInt(result[3], 16);
return r+","+g+","+b;//return 23,14,45 -> reformat if needed
}
return null;
}
console.log(rgbToHex(10, 54, 120)); //#0a3678
console.log(hexToRgb("#0a3678"));//"10,54,120"function hexToRgb(hex) {
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace(shorthandRegex, function(m, r, g, b) {
return r + r + g + g + b + b;
});
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? [
parseInt(result[1], 16),
parseInt(result[2], 16),
parseInt(result[3], 16)
] : null;
}
alert(hexToRgb("#0033ff").g); // "51";
alert(hexToRgb("#03f").g); // "51";
Also in JavaScript:
- Title
- componentWillUnmount functional component for asynchronous requests
- Category
- JavaScript
- Title
- event target javascript
- Category
- JavaScript
- Title
- arrow function component react shortcut vscode
- Category
- JavaScript
- Title
- how to english paragraph matching in javascript
- Category
- JavaScript
- Title
- get screen width javascript
- Category
- JavaScript
- Title
- how To clear all the input element inside div using jquery
- Category
- JavaScript
- Title
- go to page jquery
- Category
- JavaScript
- Title
- d3js circle out of scrren
- Category
- JavaScript
- Title
- facebook integration in node.js
- Category
- JavaScript
- Title
- export apk react native
- Category
- JavaScript
- Title
- array insertion javascript
- Category
- JavaScript
- Title
- angular themeable components
- Category
- JavaScript
- Title
- dynamodb get all items nodejs
- Category
- JavaScript
- Title
- Vue.js force to reload re-render
- Category
- JavaScript
- Title
- filtering json array in javascript
- Category
- JavaScript
- Title
- google apps script lock service
- Category
- JavaScript
- Title
- how to add object to list in javascript
- Category
- JavaScript
- Title
- if clicked outside of div jquery
- Category
- JavaScript
- Title
- input output ionic
- Category
- JavaScript
- Title
- how to find out what a string ends with in javascript
- Category
- JavaScript
- Title
- include gif in react
- Category
- JavaScript
- Title
- forward and reverse loop one by one js
- Category
- JavaScript
- Title
- Javascript check for hash in URL
- Category
- JavaScript
- Title
- convert string to char array javascript
- Category
- JavaScript
- Title
- grapejs html editor
- Category
- JavaScript
- Title
- iterate through array javascript
- Category
- JavaScript
- Title
- indexing string in javascript
- Category
- JavaScript
- Title
- Factorial
- Category
- JavaScript
- Title
- angular onchange event
- Category
- JavaScript
- Title
- express json body
- Category
- JavaScript
- Title
- import reactdom
- Category
- JavaScript
- Title
- app listen with all error handling
- Category
- JavaScript
- Title
- geolocation speed
- Category
- JavaScript
- Title
- display none after hover
- Category
- JavaScript
- Title
- async reduce javascript
- Category
- JavaScript
- Title
- .push js
- Category
- JavaScript
- Title
- display none in jquery
- Category
- JavaScript
- Title
- how to get data from localstorage in javascript
- Category
- JavaScript
- Title
- javascript call function every second
- Category
- JavaScript
- Title
- javascript array pop
- Category
- JavaScript
- Title
- como utilizar jquery
- Category
- JavaScript
- Title
- injected stylesheet remove
- Category
- JavaScript
- Title
- create new node project
- Category
- JavaScript
- Title
- angular observable subscribe and unsubscribe
- Category
- JavaScript
- Title
- compare dates in js
- Category
- JavaScript
- Title
- If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project. That will permanently disable this message but you might encounter other issues.
- Category
- JavaScript
- Title
- faker js
- Category
- JavaScript
- Title
- firebase app named default already exists react native
- Category
- JavaScript
- Title
- install php7 runtime brackets
- Category
- JavaScript
- Title
- get current screen name react navigation
- Category
- JavaScript
- Title
- angular material input
- Category
- JavaScript
- Title
- error duplicate resources react native
- Category
- JavaScript
- Title
- how to parse query string in node.js lambda
- Category
- JavaScript
- Title
- Find parent and child from array javascript
- Category
- JavaScript
- Title
- how to set up a json file
- Category
- JavaScript
- Title
- how to hide javascript element by class
- Category
- JavaScript
- Title
- check if string is datestring javascript
- Category
- JavaScript
- Title
- how to remove item from array javascript
- Category
- JavaScript
- Title
- isogram
- Category
- JavaScript
- Title
- add elements to an array with splice
- Category
- JavaScript
- Title
- comparing two arrays in javascript returning differences
- Category
- JavaScript
- Title
- how to add validator to formgroup
- Category
- JavaScript
- Title
- javacript count properties
- Category
- JavaScript
- Title
- Javascript - Track mouse position
- Category
- JavaScript
- Title
- Add table row in jQuery
- Category
- JavaScript
- Title
- graphql react filtering
- Category
- JavaScript
- Title
- how to format unix timestamp javascript
- Category
- JavaScript
- Title
- how to setstate in parent in child component in react native
- Category
- JavaScript
- Title
- how to get user ip address in javascript
- Category
- JavaScript
- Title
- interceptor in angular 8
- Category
- JavaScript
- Title
- format a date moment
- Category
- JavaScript
- Title
- array shift javascript
- Category
- JavaScript
- Title
- export aab react native
- Category
- JavaScript
- Title
- javascript change image src
- Category
- JavaScript
- Title
- combine p5 with react
- Category
- JavaScript
- Title
- disable input angular
- Category
- JavaScript
- Title
- fs create or edit file
- Category
- JavaScript
- Title
- how to import a json string from a file in typescript
- Category
- JavaScript
- Title
- compare two array javascript
- Category
- JavaScript
- Title
- addEnd Point js
- Category
- JavaScript
- Title
- how to get today date in javascript
- Category
- JavaScript
- Title
- get date one week from now javascript
- Category
- JavaScript
- Title
- datatables server side
- Category
- JavaScript
- Title
- box shadow javascript style change
- Category
- JavaScript
- Title
- ionic react use yarn
- Category
- JavaScript
- Title
- javascript change web page title
- Category
- JavaScript
- Title
- if alternative javascript
- Category
- JavaScript
- Title
- how to comment out code in react js
- Category
- JavaScript
- Title
- javascript Check if an element is a descendant of another
- Category
- JavaScript
- Title
- area of a circle
- Category
- JavaScript
- Title
- debug node
- Category
- JavaScript
- Title
- device height react native
- Category
- JavaScript
- Title
- how to redirect to another page in javascript on submit type
- Category
- JavaScript
- Title
- how to display date in javascript
- Category
- JavaScript
- Title
- angular one way property binding
- Category
- JavaScript
- Title
- conditional rendering in react
- Category
- JavaScript
- Title
- Date gethours js
- Category
- JavaScript
- Title
- chart.js data from mysql vanila javscript
- Category
- JavaScript
- Title
- javascript check if file exists in folder
- Category
- JavaScript
- Title
- how to add up all numbers in an array
- Category
- JavaScript