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

251
Views
¿Por qué la salida de un Array.prototype.map() del resultado de un Array.prototype.filter() no es una matriz?

Cuando trato de usar la función Array.prototype.some() en lo que creo que debería ser una matriz como resultado de un Array.prototype.map() de .filter() obtengo

.some no es una función

Aquí hay un breve fragmento que demuestra el error con suficiente configuración:

 // Get all options from dropdown var options = $("#mySelect option"); // Get array of strings matching regex from options var numbers = options.map(function (index, option) { return option.value.match("[0-9]+")[0]; }); // Attempt to use some on the numbers array numbers.some(function (number) { console.log(number); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <!-- Drop down menu with 10 options in words --> <select id="mySelect"> <option value="1">One 1</option> <option value="2">Two 2</option> <option value="3">Three 3</option> <option value="4">Four 4</option> <option value="5">Five 5</option> <option value="6">Six 6</option> <option value="7">Seven 7</option> <option value="8">Eight 8</option> <option value="9">Nine 9</option> <option value="10">Ten 10</option> </select>

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

0

Usted (yo) está mezclando funciones de matriz JS y funciones JQuery. El .filter() en su publicación es en realidad una función JQuery que devuelve un objeto JQuery. A partir de ahí, el mapa es otra función de JQuery que devuelve JQuery y, por lo tanto, .some() en su objeto no existe, ya que no existe como una función de JQuery.

Una solución adecuada sería usar la función JQuery .each() en lugar de esto:

 // Get all options from dropdown var options = $("#mySelect option"); // Get array of strings matching regex from options var numbers = options.map(function (index, option) { return option.value.match("[0-9]+")[0]; }); // Iterate through your object with JQuery's .each() numbers.each(function (index, number) { console.log(number); // You can return false to break this loop early similarly to .every() (or inversely to .some) on JS arrays if (number == 5){ return false; } });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <!-- Drop down menu with 10 options in words --> <select id="mySelect"> <option value="1">One 1</option> <option value="2">Two 2</option> <option value="3">Three 3</option> <option value="4">Four 4</option> <option value="5">Five 5</option> <option value="6">Six 6</option> <option value="7">Seven 7</option> <option value="8">Eight 8</option> <option value="9">Nine 9</option> <option value="10">Ten 10</option> </select>

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!