Skip to main content

Bug Tracker

Side navigation

#13689 closed bug (notabug)

Opened March 28, 2013 11:37AM UTC

Closed April 02, 2013 12:13AM UTC

Last modified April 03, 2013 07:28AM UTC

.map() - concatinates arrays

Reported by: vytautas.butkus@gmail.com Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:
Description

When using .map() method on selected elements set I want to return array as mapped value but for some reasons jQuery concatenates arrays instead of putting array into array.

Expected:

[[0,1], [2,3]]

Actual:

[0, 1, 2, 3]

I found out that you can double wrap return values to array like:

return [[0, 1]];

and then I get the desired effect but it is ugly.

If this is default behavior maybe you could implement concatenation flag on method itself like so:

.map(callback, concat = true/false)

and when concat === false you simple return the array instead of concatenating.

Attachments (0)
Change History (3)

Changed April 02, 2013 12:08AM UTC by tylercrompton comment:1

Could you please provide a code example, its expected output, and its actual output?

Changed April 02, 2013 12:13AM UTC by dmethvin comment:2

resolution: → notabug
status: newclosed

OP you are describing the documented behavior.

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. If the function returns null or undefined, no element will be inserted. -- http://api.jquery.com/map/

Changed April 03, 2013 07:28AM UTC by vytautas.butkus@gmail.com comment:3

Replying to [comment:1 tylercrompton]:

Could you please provide a code example, its expected output, and its actual output?

http://jsfiddle.net/9Zffd/4/ - here you hope, hope this helps