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

262
Views
crear matriz para cada mismo mes en javascript

Tengo una respuesta con un número de valores con el mismo mes .

Si puedes ver el de la izquierda (TAR_HEF_01,TAR_HEF_02...) son los meses y el de la derecha son los valores de los mismos.

en esto cada mes (digamos TAR_HEF_01) contiene 4 valores.

Tengo 6 meses en una matriz. Obtuve monthIndexValue a través del ciclo como se muestra a continuación.

 hebrewMonthArray.forEach((monthValue, index) => { let monthIndex = hebrewMonthArray.indexOf(hebrewMonthArray[index]); monthIndexValue = monthIndex < 9 ? `TAR_HEF_0${monthIndex + 1}` : `TAR_HEF_${monthIndex + 1}`;

Tengo un valor como el siguiente

 Object.keys(allWorkDetails).forEach((work, index) => { let value = allWorkDetails[work][monthIndexValue][0] || 0; }); });

**Aquí está la consola de monthIndexValue y value **:---

 TAR_HEF_01 0 TAR_HEF_01 0 TAR_HEF_01 0 TAR_HEF_01 0 TAR_HEF_02 0 TAR_HEF_02 0 TAR_HEF_02 0 TAR_HEF_02 0 TAR_HEF_03 0 TAR_HEF_03 0 TAR_HEF_03 0 TAR_HEF_03 0 TAR_HEF_04 0 TAR_HEF_04 0 TAR_HEF_04 0 TAR_HEF_04 0 TAR_HEF_05 0 TAR_HEF_05 0 TAR_HEF_05 0 TAR_HEF_05 0 TAR_HEF_06 90 TAR_HEF_06 9 TAR_HEF_06 -200.8 TAR_HEF_06 214.9

quiero crear una matriz para cada mes que contenga sus valores.

si pondré consola (monthIndexValue, arrayOfValue);

la salida debe ser:---

 TAR_HEF_01 [0,0,0,0] TAR_HEF_02 [0,0,0,0] TAR_HEF_03 [0,0,0,0] TAR_HEF_04 [0,0,0,0] TAR_HEF_05 [0,0,0,0] TAR_HEF_06 [90,9,-200.8,214.9]

¿Cómo puedo resolver? Gracias...

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

0

Si la respuesta es una cadena de varias líneas como la que mostró en su pregunta, pongamos su contenido en la variable de respuesta de esta manera:

 const response = `TAR_HEF_01 0 TAR_HEF_01 0 TAR_HEF_01 0 TAR_HEF_01 0 TAR_HEF_02 0 TAR_HEF_02 0 TAR_HEF_02 0 TAR_HEF_02 0 TAR_HEF_03 0 TAR_HEF_03 0 TAR_HEF_03 0 TAR_HEF_03 0 TAR_HEF_04 0 TAR_HEF_04 0 TAR_HEF_04 0 TAR_HEF_04 0 TAR_HEF_05 0 TAR_HEF_05 0 TAR_HEF_05 0 TAR_HEF_05 0 TAR_HEF_06 90 TAR_HEF_06 9 TAR_HEF_06 -200.8 TAR_HEF_06 214.9`; //now split the lines and put them in splitLines array let splitLines = response.split(/\r?\n/); let map = []; //loop through each line splitLines.forEach( (o, i) => { //parse the string to isolate month and value let parsed = o.split(" "); let parsedMonth = parsed[0]; let parsedValue = parsed[1]; //se map still doesn't contain the key parsedMonth if( typeof map[parsedMonth] === 'undefined' ){ //create a new empty array bound to the key parsedMonth in map map[parsedMonth] = []; } //add the new value to the array bound to the parsedMonth in map map[parsedMonth].push(parsedValue); });

En este punto, tiene un mapa con claves que tienen valores agrupados por mes.

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!