Is there a jQuery map utility that doesn’t automically flatten?

I was having the same problem; it turns out you can just return a nested array from within the $.map callback and it won’t flatten the outer array:

$.map([1, 2, 3], function(element, index) {
  return [ element + 1, element + 2 ];
});
=> [2, 3, 3, 4, 4, 5]

Whereas:

$.map([1, 2, 3], function(element, index) {
  return [ [ element + 1, element + 2 ] ];
});
=> [[2, 3], [3, 4], [4, 5]]

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)