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

261
Vistas
I have two array, one have N no of data and and another have fixed no of data

I have two array, one with n of data and 2nd array with fixed no of data which includes 5-6 color

Example :

Array 1 =>

const category = [
{
  name: 'Groceries',
  icon: ICONS.GROCERY,
},
{
  name: 'Bakery',
  icon: ICONS.BAKERY,
},
{
  name: 'General Stores',
  icon: ICONS.GENERAL_STORE,
},
{
  name: 'Cafe & Food',
  icon: ICONS.CAFE,
},
{
  name: 'Apparels',
  icon: ICONS.APPARELS,
},

 .
 .
 .
 .
 .
 .

];

Array 2 =>

 const bgColor = ['red', 'pink', 'blue', 'green'];

I want to merge 2 array, means i want to add background color to 1st array (category), when 2nd array elements complete its starts again with index 0

i want array like :

const category = [
{
  name: 'Groceries',
  icon: ICONS.GROCERY,
  color:"red"
},
{
  name: 'Bakery',
  icon: ICONS.BAKERY,
  color:"pink"
},
{
  name: 'General Stores',
  icon: ICONS.GENERAL_STORE,
  color:"blue"
},
{
  name: 'Cafe & Food',
  icon: ICONS.CAFE,
  color:"green"
},
{
  name: 'Cafe & Food',
  icon: ICONS.CAFE,
  color:"red"
},
{
  name: 'Apparels',
  icon: ICONS.APPARELS,
  color:"pink"
},

 .
 .
 .
 .
 .
 .

];
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

To get circular index you can use remainder operator (%) where max index is the length of colors array:

categories.map((category, index) => {
  const circularIndex = index % bgColors.length
  return {...category, color: bgColors[circularIndex] }
})
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