#6183 closed bug (wontfix)
$.map flattens arrays
Reported by: | nlogax | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | 1.4.3 |
Component: | core | Version: | 1.4.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Mapping function(x) { return x; } over an array should result in an identical array. Using the Array map method, this works as expected: 1,2,3], ['a','b','c'?.map(function(x) { return x; }) -> 1,2,3], ['a','b','c'? Using jQuery.map, this happens: $.map(1,2,3], ['a','b','c'?, function(x) { return x; }) -> [1, 2, 3, 'a', 'b', 'c']
Change History (5)
comment:1 Changed 13 years ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:2 Changed 12 years ago by
This is really broken for a map function. It shouldn't flatten or remove nulls, whether or not it says it's broken in the documentation.
comment:3 Changed 11 years ago by
It would be interesting to understand why the implementation needs to flatten arrays and why we can't control the behavior with an optional param. If you attempt to use the map function on an array of arrays, this behavior is inappropriate. If you review the comments on the map page, a number of people find this non-obvious and unexpected flattening to be a problem. It's easy enough to wrap your value in a new array to work around the problem, but it feels like a hack.
comment:4 Changed 11 years ago by
Priority: | → undecided |
---|
It would be interesting to understand why the implementation needs to flatten arrays and why we can't control the behavior with an optional param.
First and foremost, $.map is a utility function intended for our own use with DOM elements; we need it to flatten arrays and remove nulls. We're not interested in functionality that would add size and reduce performance if we don't need it.
An Array-wrapped array seems less funky than passing a boolean argument that changes the behavior, and it's fully backward-compatible.
comment:5 Changed 11 years ago by
Component: | misc → core |
---|---|
Priority: | undecided → low |
Yep, that's intended - it's even mentioned in the docs: http://api.jquery.com/jQuery.map/