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

289
Vistas
first element is not pushing inside empty array in reactJS?

trying to push data coming to "id" to "selectedUserId" array, but first element is not inserting. selectedUserId array does not contain first pushed element, push is only working from second element onwards.

   const handleSelectOne=(e)=>{
   const id = e.target.value;
 
   console.log(id,"handling")
   
   if(!selectedUserIds.includes(id))
   {
     selectedUserIds.push(id)
   }
   else 
   {
     selectedUserIds.pop(id)
   }
   
   setCheckedStatusOne(!checkedStatusOne[id])

   }


const handleDeleteSelectedClick=() =>{
   
let deletionItemsNo = selectedUserIds.length

selectedUserIds.map((id)=>{
 
  return console.log(id, "<== element inside selecteduserids array")
})
console.log(deletionItemsNo, "<== number of elements in array")
}

output console output

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

0

.pop() method doesn't accept any arguments. It used for removing the last array item.

To be able to insert element in the beginning you should use .unshift(id)

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