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

108
Vistas
React array.slice multiple endpoints

Is it possible to get first 3 and last 2 items using array.slice in js

I want to render all data if user is AUTH, and if not I want first 3 and last 2 from array without recreating array.

 {menu.slice(...(auth ? [0, 5] : //THERE SHOULD FIND FIRST 3 AND LAST 2 )).map((item) => (
      <Link
        onClick={() => dispatch(handleMenu())}
        to={item.path}
        className={`${auth === false && "font-md"} ${
          item.path === window.location.pathname && "font-2xl"
        }`}
      >
        {item.title}
      </Link>
    ))}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Yes, it is possible to get first 3 items and last 2 items;

example:

let arr = ["a", "b", "d", "c", "e", "f", "g", "h", "i"];

To get first 3 items:

arr.slice(0, 3);

To get last 2 items:

arr.slice(-2);

As you wanted to add both of the slices and render them, this might help you:

arr.slice(0, 3).concat(arr.slice(-2));
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