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

156
Vistas
How to array.splice from both ends simultaneously in Javascript?

How do you splice from both ends of an array either simultaneously or sequentially such that "leftsplice" number of fields are spliced from left and "rightsplice" number of fields are spliced from original array not the one after doing leftsplicing. Any tips?

  const [skillname,setSkillName] = useState(["Engineering", "Product", "Organization", "Business", "Market", "Customer"]);
    setSkillName(skillname => skillname.splice(0,leftsplice))
    let temp=-5+leftsplice;
    setSkillName(skillname => skillname.splice(temp, rightsplice))

This is doing only leftsplicing. PS: leftsplice, rightsplice are working as desired. I console.logged them

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

0

Your code in splicing is okay, but you should only use setSkillName after both leftsplice and rightsplice is done by saving it on a temporary variable, I haven't tested this code below but it is answering the question "How to splice both at the same time from a state" :

function whatever() {
  let tempSkillName = [...skillname]
  tempSkillName = tempSkillName.splice(0,leftsplice))
  let temp=-5+leftsplice;
  tempSkillName = tempSkillName.splice(temp, rightsplice))
  setSkillName(tempSkillName)
}
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