RGB to array

OSCC · JavaScript, String, Browser, Regexp · Jun 13, 2021

Converts an rgb() color string to an array of values.

const toRGBArray = rgbStr => rgbStr.match(/\d+/g).map(Number);
toRGBArray('rgb(255, 12, 0)'); // [255, 12, 0]

Recommended snippets & collections

  • Working with color in JavaScript requires some understanding of color formats and conversions. Luckily, this snippet collection's got you covered.

  • RGB to object

    JavaScript, String

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

  • HSL to array

    JavaScript, String

    Converts an hsl() color string to an array of values.

  • HSL to object

    JavaScript, String

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