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

118
Views
Assigning different colors to each element in an array

I have a variable named "classes" and basically, it contains classes like (apples,orange,grapes,mango) and this is coming from a txt file and being stored in a variable. The elements are printed on the webpage,but I want to assign each element in the set a different colour and I cant use random() because it will keep changing after i refresh the page, what I want to achieve is assigning random colours to each element in the Set and then the colours should become static and shouldn't keep changing after that.

Can someone please help how to achieve this either through html,css,or javascript.I am a beginner and I have to achieve this task fast.

Thank you

...

 <p id="classname"  ></p>



  #classname{
      text-align: right;
           }

  


                classes = annotationline[8];
                //pushing the elements in an array
               classarray.push(classes);
               //removing duplicates
                classset=new Set(classarray);
                console.log(classset);
                //printing it
                text = "";
                classset.forEach (function(value) {

                  text += value + "<br>";

                })
                    document.getElementById("classname").innerHTML = text;
                classarray.length = 0;
               })

...

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!