开发者

Concating two arrays results in nested array when one is constructed via map

开发者 https://www.devze.com 2023-02-20 13:18 出处:网络
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:

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 aler开发者_StackOverflow社区ts 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.


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

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

It return a jQuery object.

0

精彩评论

暂无评论...
验证码 换一张
取 消