0

I'm looking to streamline this code using a loop.

a = new Array("green","blue","pink","white");

b = new Object();
b.green = 21;
b.blue = 22;
b.pink = 23;
b.white = 24;

for(n=0; n<=3; n++){
  // Code would look like below but a[n] would be the array name, i.e b.red = (21+n) and loop through the other colours.
  b.a[n] = (21+n);
};

Instead of writing code like the above is a way it can be included in a loop?

S.S
  • 5
  • 4

0 Answers0