I think only the inner-most loop needs the push:
for (x = 0; x < R.length; x++){
for (y = 0; y < G.length; y++){
for (z = 0; z < B.length; z++){
pallet[j] = "#"+R[x]+G[y]+B[z];
j++;
}
}
}
OR
for (x = 0; x < R.length; x++){
for (y = 0; y < G.length; y++){
for (z = 0; z < B.length; z++){
pallet.push("#"+R[x]+G[y]+B[z]);
}
}
}
The count should be 216. 6*6*6 = 216. The undefined values were in there because the loop variable, z
for instance, gets incremented the last time it exits the loop. So after the loop was complete, you were referencing the variable at which point the value would be 1 more than the length of the array, resulting in the undefined value.
update To clarify
for (x = 0; x < R.length; x++){
for (y = 0; y < G.length; y++){
for (z = 0; z < B.length; z++){
pallet[j] = "#"+R[x]+G[y]+B[z];
j++;
}
//remove ==> pallet[j] = "#"+R[x]+G[y]+B[z];
//remove ==> j++;
}
//remove ==> pallet[j] = "#"+R[x]+G[y]+B[z];
//remove ==> j++;
}