当前位置: 动力学知识库 > 问答 > 编程问答 >

How to insert an Object as an Array element in javascripts

问题描述:

This question already has an answer here:

  • How to add an object to an array

    11 answers

网友答案:

You can push it or just use the literal.

var studentsArray = [student1, student2];
// or studentArray.push(student1, student2);

Printing the names would be simple

studentsArray.forEach(function(student){
   alert(
          // display the appropriate property of student
        );
});
分享给朋友:
您可能感兴趣的文章:
随机阅读: