Javascript Data Type How to - Get the complete list of hexadecimal color numbers using a loop








Question

We would like to know how to get the complete list of hexadecimal color numbers using a loop.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
var colors = [];
for (var i = 0; i < 300; i++) {
    colors.push("#" + ("000000000" + i.toString(16)).slice(-6));
}<!--from  w w  w. ja v a  2s . c  o m-->
document.writeln(JSON.stringify(colors));

</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: