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

161
Views
JSON array splitting React JS

I have a JSON array in my state and I want to use the other half of it. For example if the size of the JSON array is 10, I am interested in to access the later 5 values. How can I achieve that? I have tried many solutions but I always end up getting errors. I am working with React JS. So I was using map function but I am unable to fulfill my condition.

  data.map((item, index) => {

I am unable to use reduce or filter I tried that also.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

As @SaeedShamloo mentioned slice method will be sufficient here

data.slice(Math.floor(data.length/2), data.length).map(item => )
about 4 years ago · Santiago Trujillo Report

0

Use filter by array indexes.

const data = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15];

const res = data.filter((_, idx, arr) => idx >= arr.length / 2);

console.log(res);


// Alternatively
const res2 = data.slice(-data.length/2);

console.log(res2);

about 4 years ago · Santiago Trujillo 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!