Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!