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

162
Views
División de matriz JSON React JS

Tengo una matriz JSON en mi estado y quiero usar la otra mitad. Por ejemplo, si el tamaño de la matriz JSON es 10, me interesa acceder a los 5 valores posteriores. ¿Cómo puedo lograr eso? He intentado muchas soluciones, pero siempre termino obteniendo errores. Estoy trabajando con React JS. Así que estaba usando la función de mapa pero no puedo cumplir con mi condición.

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

No puedo usar reducir o filtrar. También lo intenté.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Como @SaeedShamloo mencionó que el método de slice será suficiente aquí

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

0

Utilice el filter por índices de matriz.

 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!