iterate through colors in javascript

前端 未结 3 844
终归单人心
终归单人心 2021-01-06 09:02

I want to make a list of all colors used in css, however they seem to be stored in a base 16 format. I thought something like this might work, but it does not do what I wan

3条回答
  •  天命终不由人
    2021-01-06 09:36

    In JavaScript you can use "0x" before a number to make it hexadecimal and "0" to make it octal. Using this method, this should be the best code. This will probably crash your web browser, as there are 16,581,375 different possible hexadecimal colors in all of CSS. That's more than there are bytes in a megabyte (about 1 million), or how many years it would take to crack a 17-lowercase letter password.

    var colors = new Array();
    for(col=0x0;col<=0xFFFFFF;col++) {
      colors.push("#" + col);
    }
    

提交回复
热议问题