Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda