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

177
Views
La unión de Javascript no funciona en la matriz creada

Problema extraño al unirse. Funciona en la matriz inicial, pero no con la matriz filtrada. Probado también funciona para cadena, pero resultA tampoco es cadena.

¿Qué está mal con el código:

 const constants = [2, 2, 4, 2, 6, 4, 7, 8]; const stdFound = []; // Makes list of indexes - positions from matching value 2 in constants constants.filter(function(elem, index, array) { if (elem == (2)) { stdFound.push(index); } }); //Makes new array from results by indexes found const resultA = [constants.filter((x, i) => stdFound.includes(i))]; document.getElementById("resultA").innerHTML = resultA; //Makes string by join document.getElementById("resultJ").innerHTML = resultA.join(" x ");
 <p> ARRAY : <span id="resultA"></span> <p> JOIN x : <span id="resultJ"></span></p>

En este momento, este código da como resultado: ARRAY: 2,2,2 JOIN x: 2,2,2

tan claramente, unirse no está funcionando.

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

0

filter() ya devuelve una matriz. No es necesario envolver en este [] .

console.log(resultA) lo mostrará.

 const constants = [2, 2, 4, 2, 6, 4, 7, 8]; const stdFound = []; // Makes list of indexes - positions from matching value 2 in constants constants.filter(function(elem, index, array) { if (elem == (2)) { stdFound.push(index); } }); //Makes new array from results by indexes found const resultA = constants.filter((x, i) => stdFound.includes(i)); document.getElementById("resultA").innerHTML = resultA; //Makes string by join document.getElementById("resultJ").innerHTML = resultA.join(" x ");
 <p> ARRAY : <span id="resultA"></span> <p> JOIN x : <span id="resultJ"></span></p>

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!