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

132
Vistas
How to remove elements of array in order of index range?

I have an array:

const savings = ["+10$", "-22.50$", "+5$", "+22.40$", "-3.5$"]; 

I want to show elements only in a certain range of array indexes. For example: how to show everything between array index 1 (-22.50$) and array index 3 (+22.50$)? All elements with lower or higher indexes should be removed.

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

0

There are many ways to do so:

slice (returns new array)

savings.slice(1,4) // ['-22.50$', '+5$', '+22.40$']

splice (modifies array)

savings.splice(1,3) // ['-22.50$', '+5$', '+22.40$']


...plus many other more complicated techniques including but not limited to:

filter (returns new array)

in this case it's effectively just a .slice.

// ['-22.50$', '+5$', '+22.40$']
savings.filter((price, index) => index >= 1 && index <= 4)
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