Bug Tracker

Opened 9 years ago

Closed 9 years ago

#14409 closed bug (notabug)

.map(fn).toArray() and .map(fn).get() will flatten inner arrays

Reported by: [email protected] Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:


Mapping over a selection with a function that returns arrays will flatten all returned values into a 1d array, instead of returning a 2d array as expected.

To reproduce:

$('<p/>').map(function() { return [1,2]; }).get(); // [1,2]
$('<p/><p/>').map(function() { return [1,2]; }).get(); // [1,2,1,2]

Change History (1)

comment:1 Changed 9 years ago by dmethvin

Resolution: notabug
Status: newclosed

instead of returning a 2d array as expected.

Was that expected after reading the docs?

The function can return an individual data item or an array of data items to be inserted into the resulting set. If an array is returned, the elements inside the array are inserted into the set. -- http://api.jquery.com/map/

Note: See TracTickets for help on using tickets.