Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#13689 closed bug (notabug)

.map() - concatinates arrays

Reported by: vytautas.butkus@… 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.

Change History (3)

comment:1 Changed 7 years ago by tylercrompton

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

comment:2 Changed 7 years ago by dmethvin

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/

comment:3 in reply to:  1 Changed 7 years ago by vytautas.butkus@…

Replying to 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

Note: See TracTickets for help on using tickets.