Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
Using Javascript to loop over an object and change details

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!