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

232
Vistas
How to append deleted from array elements by slice method?

How to delete elements from start of array and append them into end ? enter image description here

  const ImageArray = [i1,i2,i3,i4,i5]

  const clickHandler = (index: number) => {
        let start = ImageArray.slice(index)
        let end = ImageArray....
        let result = start.concat(end)
        return result
    }

    {ImageArray.map((image, index) => (
                <div
                    onClick={() => clickHandler(index)}
                    key={index} style={{backgroundImage: 'url('+image+')'}}
                />
            ))}

P.S. It's not necessary to use slice method

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

0

With x being the index clicked :

const arr = [0,1,2,3,4];
const newArr = [...arr.slice(1), ...arr.slice(0, 1)]
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can do:

const arr = ['i1','i2','i3','i4','i5']
const clickHandler = i => [...arr.slice(i), ...arr.slice(0, i)]

console.log('i3:', clickHandler(2)) // Clicked: 'i3'

about 4 years ago · Juan Pablo Isaza Denunciar

0

Your function is designed to return a new array, but the place where you call the function is not doing anything with the returned value.

I assume you want to mutate ImageArray. In that case use splice to delete the first part, and push to append that same part at the end:

const clickHandler = (index: number) => {
    ImageArray.push(...ImageArray.splice(0, index));
};
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