最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery.map(....).concat is not a function - Stack Overflow

programmeradmin0浏览0评论

Why would the following jquery code sometimes throw the error "concat is not a function":

var myArray = $('div.foo')
    .filter(function() { return $(this).is('.something'); })
    .map(function() { 
        return [['a', 'b', $(this).val()]];
    });

return myArray.concat(anotherArray);

Why would the following jquery code sometimes throw the error "concat is not a function":

var myArray = $('div.foo')
    .filter(function() { return $(this).is('.something'); })
    .map(function() { 
        return [['a', 'b', $(this).val()]];
    });

return myArray.concat(anotherArray);
Share Improve this question asked Sep 20, 2012 at 2:18 cbpcbp 25.6k29 gold badges132 silver badges211 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

$().map() returns a jQuery object, not an array.
jQuery objects do not have a concat() method.

You need to call .get() to get a real array.

contact is for ARRAYS, and not for OBJECTS. Use:
1) Filter Form Parameters Before Submitting
Or
2) How can I merge properties of two JavaScript objects dynamically?

发布评论

评论列表(0)

  1. 暂无评论