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.

Share and Enjoy

  • Facebook
  • Twitter
  • Google Plus
  • Live
  • Delicious
  • Digg
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS
  • Instapaper
  • FriendFeed