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

128
Views
JS create rating score from 2 loops/arrays

I am trying to create a basic rating component that looks like this:

◼◼◼◻◻ (score: 3 out of 5)

I have the following code in JSX:

var score = 3; 
var range = 5;

{ [...Array(range)].map((e, i) => (
  <div className="rating-item" data-rating-count={ i + 1 }></div>
)) }

this returns the range but doesn't show the rating score:

◻ ◻ ◻ ◻ ◻ 

How can I combine the score and range values and add a class name active to the rating items?

I'm trying to get the following HTML:

<div class="rating-item active" data-rating-count="1"></div>
<div class="rating-item active" data-rating-count="2"></div>
<div class="rating-item active" data-rating-count="3"></div>
<div class="rating-item" data-rating-count="4"></div>
<div class="rating-item" data-rating-count="5"></div>

Which will output: ◼◼◼◻◻

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think You need to modify your code like this

var score = 3; 
var range = 5;

{ [...Array(range)].map((e, i) => (
  <div className={"rating-item " + (i < score ? "active": "")} data-rating-count={ i + 1 }></div>
)) }
about 4 years ago · Juan Pablo Isaza Report
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!