0

I am trying to concat two arrays using the concat-method.

However, if one of them if constructed using jQuery's "map" method, I receive a nested array:

var first = [];
var second = $("").map(function (e, i) { return null; }); ;

var result = first.concat(second);
alert(result.length);
alert(result[0]);

The output of the alerts are "1" respectively "[object Object]" while I would expect "0" and "undefined".
The debugger shows that result is "[ [ ] ]".

What's wrong here?
The documentation clearly states that map returns an array.

1 Answer 1

2

You are linking to the wrong method. Here is the method you are using:

http://api.jquery.com/map/

It return a jQuery object.

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

1 Comment

Thanks. I just needed to add a call to jQuery.makeArray() to fix it.

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.