Q:

jQuery's .map() returns array, not a matched set (jQuery object)

When using the .map() method, I'm getting back an array with two nodes I think (not an jQuery object/matched set). I want to apply a class this set but nothing happens.
$('input#substance, input[name="atc_code"]').map(function() {return $(this).prevAll('label:first')});

Returns:
[x.fn.x.init[1], x.fn.x.init[1]]

[
x.fn.x.init[1]
0: label
context: input#substance.ui-autocomplete-input
length: 1
prevObject: x.fn.x.init[1]
__proto__: Object[0]
, 
x.fn.x.init[1]
0: label
context: input.small ui-autocomplete-input
length: 1
prevObject: x.fn.x.init[1]
__proto__: Object[0]

It selects correctly but why can't I use this array? Why is it not a jQuery object?
The HTML:
<div class="fieldset-container">
   <label>Substance</label>
   <span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span> 
   <input type="text" name="substance" id="substance" maxlength="22" autocomplete="off" spellcheck="false" autofocus="autofocus" class="ui-autocomplete-input">

   <label title="Required field">ATC code<span class="ma">*</span></label>
   <span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span><input type="text" class="small ui-autocomplete-input" name="atc_code" maxlength="7" autocomplete="off" spellcheck="false">

   <label>Year</label>
   <div class="small">
      <select name="year">...</select>
   </div>
</div>

A:

It selects correctly but why can't I use this array? Why is it not a jQuery object?

It is, but this is one of those confusing times when the elements within the jQuery object are, themselves, jQuery objects. 99.999% of the time, a jQuery set contains DOM elements, but it's possible to have jQuery sets containing other things. In particular, when you use .map, the resulting jQuery object contains whatever your mapping function returns, unchanged. In your case, you were returning jQuery objects from your mapping function, and so that's what was in your resulting jQuery set. (And if that isn't confusing enough, jQuery also has two different map methods: The one that's specific to instances and that returns a jQuery object, which is the one you used, and one that's not specific to an instance and returns an array.)
You can solve this by having your mapping function return raw DOM elements:
$('input#substance, input[name="atc_code"]').map(function() {return $(this).prevAll('label:first')[0]});
// The new bit -----------------------------------------------------------------------------------^^^

Live Example | Live Source
Alternately, you can do this without .map:
$('input#substance').prevAll('label').first().add(
  $('input[name="atc_code"]').prevAll('label').first()
);

Live Example | Live Source

