A simple nested RGB loop will not generate your red-yellow-green-blue gradient. If this is really what you specifically want, then you should learn a little about the color wheel:
red
|
magenta__ | __yellow
\|/
__/|\__
blue | green
|
cyan
HSV, . , , . , :
function cssColor (r, g, b) {
return 'rgb('+r+','+g+','+b+')';
}
var colors = [];
var r = 255;
var g = 0;
var b = 0;
for (var g=0;g<=255;g++) colors.push(cssColor(r,g,b));
for (var r=255;r>=0;r--) colors.push(cssColor(r,g,b));
for (var b=0;b<=255;b++,g--) colors.push(cssColor(r,g,b));
768 . , 100 :
var subColors = [];
for (var i=0;i<colors.length;i++) {
if (i%8 == 0) subColors.push(colors[i]);
}
, , .