HSL to array

OSCC · JavaScript, String, Browser, Regexp · Oct 22, 2020

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

const toHSLArray = hslStr => hslStr.match(/\d+/g).map(Number);
toHSLArray('hsl(50, 10%, 10%)'); // [50, 10, 10]

Recommended snippets & collections

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

  • HSL to object

    JavaScript, String

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

  • RGB to array

    JavaScript, String

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

  • RGB to object

    JavaScript, String

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