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

89
Views
¿Puedo usar instrucciones repetidas en los datos?

es posible?

Quiero crear datos de objetos continuos.

  • lo que quiero

     return [ { text: '2', align: 'center', value: '2', sort: false }, { text: '3', align: 'center', value: '3', sort: false }, { text: '4', align: 'center', value: '4', sort: false }, { text: '5', align: 'center', value: '5', sort: false }, { text: '6', align: 'center', value: '6', sort: false }, { text: '7', align: 'center', value: '7', sort: false }, { text: '8', align: 'center', value: '8', sort: false }, ]
  • mi reflexion

     return [ () => { for (let i = 0; i >= 8; i++) { return { text: i, align: 'center', value: i >= 10 ? `day${i}` : `day0${i}`, sort: false, } } }, ]

Pero esto, por supuesto, no funcionó. ¿Cómo puedo hacerlo de esta manera?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Puede hacer esto llenando una matriz vacía de la cantidad de elementos que desee y luego usando el map y el índice de cada elemento vacío:

 const result = new Array(35).fill(0).map((_, i) => ({ text: i, align: 'center', value: i >= 10 ? `day${i}` : `day0${i}`, sort: false, })); console.log(result);

about 4 years ago · Juan Pablo Isaza Report

0

Puede declarar una pequeña función de ayuda que llama a una función para ( mapas sobre ) un rango dado de enteros, así:

 function mapRange(min, max, fn) { const out = []; for (let i = min; i < max; i++) { out.push(fn(i)); } return out; }

Entonces puedes simplemente

 const result = mapRange(0, 35, (i) => ({ text: i, align: 'center', value: i >= 10 ? `day${i}` : `day0${i}`, sort: false, }));

(Según una prueba de JSBench, esto es aproximadamente un 20 % más rápido que la solución similar de Jamiec que utiliza el new Array().fill().map() .)

about 4 years ago · Juan Pablo Isaza Report

0

Las otras respuestas son demasiado largas... inútiles... Intente

 [...Array(7)].map((_, i) => ({ text: `${i+2}`, align: 'center', value: `${i+2}`, sort: false }));
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!