JS declare an array and add an object variable to an array simple example _javascript tips

Source: Internet
Author: User

Arrays are defined in four different ways

Using constructors:

var a = new Array ();
var B = new Array (10);
var c = new Array ("A", "second", "third");

or the direct amount of the array:

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

Extended:

function Objstory (id,biaoti,author,type)//Declaration object
{
    this.id = ID;
    This. Biaoti= Biaoti;
    This. Author= Author;
    This. type = type;
    

}

var arr = new Array ()//Declaration array, used to store header information

var writer= new Objstory (11, ' Everyone go to see the sea ', ' Li Bold ', ' literary class ');/Declare object
Arr[0]=writer ;//Add objects to the collection

Another method:

var array=[];

Array.push (New Objstory (12, ' Everyone goes to see the sea ', ' Lee Bold ', ' literary class '));

Array.push (New Objstory (14, ' everyone to see the day ', ' Li Xiao ', ' literary class '));

The above JS declaration of the array and add object variables to the array of simple examples is the small series to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.