Defining an array in JavaScript

There are 3 ways of defining an array in JavaScript

  1. Conventional arrayThe classic conventional array looks like the following:
    var mystudents=new Array()

    You can expand and contract the array as desired, by adding new array
    elements. Note that like in most other programming languages, the first array
    element should have an index number of 0.

    With a conventional array, you have the option of presetting the array’s
    length when defining it, by passing in a numeric integer into the Array()

    var mystudents=new Array(3)

    In this case 3 array elements will automatically be created, each with a
    value of “undefined.” It also means probing the property
    mystudents.length will return 3.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s