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

68
Views
Se agregó contenido a la matriz, pero todavía está vacía

Mi código

 const upperCase = 'QWERTYUIOPASDFGHJKLZXCVBNM'.split(''); const lowerCase = 'qwertyuiopasdfghjklzxcvbnm'.split(''); const numbers = '1234567890'.split(''); const symbols = '@#£&*()\'"%-+=/;:,.€$¥_^[]{}§|~…\\<>!?'.split(''); var exclude = []; var fullList = []; var allowUpperCase = true; var allowLowerCase = true; var allowSymbols = true; var allowNumbers = true; function genList() { if (allowUpperCase) { fullList.concat(upperCase); } if (allowLowerCase) { fullList.concat(lowerCase); } if (allowSymbols) { fullList.concat(symbols); } if (allowNumbers){ fullList.concat(numbers) } } genList(); console.log(fullList);

Lo que se supone que debe hacer: básicamente verificar si el usuario quiere esos caracteres y luego agregarlos a la matriz "fullList"

Pero luego, cuando hago genList y console.log(fullList) , parece estar vacío []

¿Por qué?

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

0

Como está buscando mutar la matriz fullList , puede usar Array#push() y distribuir la matriz pasada en lugar de usar Array#concat() .

Esto evita crear una nueva matriz en cada coincidencia de condición y simplemente amplía la matriz existente.

 const upperCase = 'QWERTYUIOPASDFGHJKLZXCVBNM'.split(''); const lowerCase = 'qwertyuiopasdfghjklzxcvbnm'.split(''); const numbers = '1234567890'.split(''); const symbols = '@#£&*()\'"%-+=/;:,.€$¥_^[]{}§|~…\\<>!?'.split(''); var exclude = []; var fullList = []; var allowUpperCase = true; var allowLowerCase = true; var allowSymbols = true; var allowNumbers = true; function genList() { if (allowUpperCase) { fullList.push(...upperCase); } if (allowLowerCase) { fullList.push(...lowerCase); } if (allowSymbols) { fullList.push(...symbols); } if (allowNumbers) { fullList.push(...numbers) } } genList(); console.log(fullList.join(', '));

about 4 years ago · Juan Pablo Isaza Report

0

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat

El método Array Concat no modifica la matriz actual, pero devuelve una nueva. Modifique el método de esta manera y funcionará.

 function genList() { if (allowUpperCase) { fullList = fullList.concat(upperCase); } if (allowLowerCase) { fullList = fullList.concat(lowerCase); } if (allowSymbols) { fullList = fullList.concat(symbols); } if (allowNumbers){ fullList = fullList.concat(numbers) } }
about 4 years ago · Juan Pablo Isaza Report

0

El método de matriz concat ( ver MDN Web Docs ) no cambia la matriz original, devuelve una nueva matriz.

 const upperCase = 'QWERTYUIOPASDFGHJKLZXCVBNM'.split(''); const lowerCase = 'qwertyuiopasdfghjklzxcvbnm'.split(''); const numbers = '1234567890'.split(''); const symbols = '@#£&*()\'"%-+=/;:,.€$¥_^[]{}§|~…\\<>!?'.split(''); var exclude = []; var fullList = []; var allowUpperCase = true; var allowLowerCase = true; var allowSymbols = true; var allowNumbers = true; function genList() { if (allowUpperCase) { fullList = fullList.concat(upperCase); } if (allowLowerCase) { fullList = fullList.concat(lowerCase); } if (allowSymbols) { fullList = fullList.concat(symbols); } if (allowNumbers){ fullList = fullList.concat(numbers); } console.log(fullList); } genList();

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!