Jquery 未捕获类型错误:追加不是函数

Jquery 未捕获类型错误:追加不是函数,jquery,Jquery,我想创建一个“人员”数组,并将其记录到控制台 这是我的代码: $(document).ready(function () { function Person(firstName) { this.firstName = firstName; console.log('Person instantiated'); } var people = new Array; people.append(new Person("Alice1"));

我想创建一个“人员”数组,并将其记录到控制台

这是我的代码:

$(document).ready(function () {
    function Person(firstName) {
        this.firstName = firstName;
        console.log('Person instantiated');
    }
    var people = new Array;
    people.append(new Person("Alice1"));
    people.append(new Person("Alice2"));
    people.append(new Person("Alice3"));
    people.append(new Person("Alice4"));

    for (var i = 0; i < people.length; i++) {
        console.log(people[i]);
    }
});
$(文档).ready(函数(){
职能人员(名字){
this.firstName=firstName;
log('Person instantiated');
}
var-people=新数组;
人物。附加(新人物(“Alice1”);
人物。附加(新人物(“Alice2”);
人物。附加(新人物(“Alice3”);
人员。追加(新人员(“Alice4”);
for(var i=0;i
但是,控制台显示了以下内容:

main.js:4 Person instantiated
jquery-3.1.1.min.js:2 jQuery.Deferred exception: people.append is not a function TypeError: people.append is not a function
    at HTMLDocument.<anonymous> (http://localhost:8383/p5/js/main.js:7:8)
    at j (http://localhost:8383/p5/js/jquery-3.1.1.min.js:2:29948)
    at k (http://localhost:8383/p5/js/jquery-3.1.1.min.js:2:30262) undefined
r.Deferred.exceptionHook @ jquery-3.1.1.min.js:2
k @ jquery-3.1.1.min.js:2
jquery-3.1.1.min.js:2 Uncaught TypeError: people.append is not a function
    at HTMLDocument.<anonymous> (main.js:7)
    at j (jquery-3.1.1.min.js:2)
    at k (jquery-3.1.1.min.js:2)
(anonymous) @ main.js:7
j @ jquery-3.1.1.min.js:2
k @ jquery-3.1.1.min.js:2
main.js:4人实例化
jquery-3.1.1.min.js:2 jquery.延迟异常:people.append不是函数类型错误:people.append不是函数
在HTMLDocument。(http://localhost:8383/p5/js/main.js:7:8)
在j(http://localhost:8383/p5/js/jquery-3.1.1.min.js:2:29948)
在k(http://localhost:8383/p5/js/jquery-3.1.1.min.js:2:30262)未定义
r、 Deferred.exceptionHook@jquery-3.1.1.min.js:2
k@jquery-3.1.1.min.js:2
jquery-3.1.1.min.js:2未捕获类型错误:people.append不是函数
在HTMLDocument。(main.js:7)
在j处(jquery-3.1.1.min.js:2)
在k处(jquery-3.1.1.min.js:2)
(匿名)@main.js:7
j@jquery-3.1.1.min.js:2
k@jquery-3.1.1.min.js:2
我在初始化主js文件之前的HTML文件中的
jquery.min.js
,那么是什么导致了这种情况呢

TypeError:people.append不是函数

这意味着
append
不是方法,因此您应该使用将元素添加到数组中:

people.push(new Person("Alice1"));
希望这有帮助

$(文档).ready(函数(){
职能人员(名字){
this.firstName=firstName;
log('Person instantiated');
}
var-people=新数组;
推送(新人(“Alice1”);
推送(新人(“Alice2”);
推送(新人(“Alice3”);
推送(新人(“Alice4”);
for(var i=0;i

,因为数组没有append。。。。这与jquery没有什么关系-javascript的工作方式存在明显的误解。谢谢,这已经解决了它!