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

250
Views
Why is the output from a Array.prototype.map() of the result of a Array.prototype.filter() not an array?

When I try to use the Array.prototype.some() function on what I think should be an array as the result of an Array.prototype.map() from .filter() I get

.some is not a function

Here is a short snippet demonstrating the error with sufficient setup:

// 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

You (I) are mixing up JS array functions and JQuery functions. The .filter() in your post is actually a JQuery function that returns a JQuery object. From there, map is another JQuery function returning JQuery and thus .some() on your object does not exist as it does not exist as a JQuery function.

A suitable solution would be to use the JQuery .each() function instead like this:

// 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!