Skip to content

Home

RGB to object

Converts an rgb() color string to an object with the values of each color.

const toRGBObject = rgbStr => {
  const [red, green, blue] = rgbStr.match(/\d+/g).map(Number);
  return { red, green, blue };
};

toRGBObject('rgb(255, 12, 0)'); // {red: 255, green: 12, blue: 0}

More like this

Start typing a keyphrase to see matching snippets.