js Declare arrays and add simple instances of object variables to arrays

  • 2021-07-06 09:47:04
  • OfStack

Arrays are defined in four ways

Using the constructor:

var a = new Array();
var b = new Array(10);
var c = new Array("first", "second", "third");

Or array direct quantity:

var d = ["first", "second", "third"];


function ObjStory(id,biaoti,author,type) // Declare an object 
    this.ID = id;
    this.Biaoti= biaoti;
    this.Author= author;
    this.Type = type;


var arr = new Array();// Declare an array to store header information 

var writer= new ObjStory(11, 'Everybody go to see the sea ', 'Li Dadan ', 'Literature and art ');// Declare an object 
arr[0]=writer;// To add an object to a collection 

Another method:

var Array=[];

Array. push (new ObjStory (12, 'Let's see the sea', 'Li Dadan', 'Literature and art'));

Array. push (new ObjStory (14, 'Let's see the sky', 'Li Xiaodan', 'Literature and art'));

Related articles: