1

I try to learn jQuery.map() and something i misunderstand

Why...

var arr = [0];
arr = $.map(arr, function(a,i) {
  return [a,i];
});

Return [0, 0] ,Why not [[0,0]]

but normally

var arr = [0];
arr = [arr,0];

Return [[0], 0]

http://jsbin.com/uhixex/1/edit

Seems like stupid qustion, But expain me pls

0

1 Answer 1

4

The documentation for the callback in jQuery 1.6+ says:

A returned array will be flattened into the resulting array

Which basically means that if your map results in a nested array, the nesting will be discarded and a single-dimension array will be returned.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.