#13689 closed bug (notabug)
.map() - concatinates arrays
Reported by: | 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 follow-up: 3 Changed 10 years ago by
comment:2 Changed 10 years ago by
Resolution: | → notabug |
---|---|
Status: | new → closed |
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 Changed 10 years ago by
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
Could you please provide a code example, its expected output, and its actual output?