SHARE

What Is Array

Programming languages provides a data structure called the array. It can store a fixed-size sequential collection of elements of the same type. In the article read this at lower section .

In the short description (1) It is as collection of same type variables (2) It is a variable which store multiple values .

Read the article what is variable

It a method of storing several items in computer programming .It just like variable .  The only difference is in an array multiple items are stored .

array index chart
array index chart

Features

In an Array all stored items must be the same types . Suppose in It you can save one integer value , then other elements can must be integers .

How To Use It

In and array store multiple items with same type . Suppose 6 items stored in It . All these items are indexed with number (0,1,2 ……5 ) by the programming language .

Index number 0 is first item of array and index number last item . When you call index number 0 during code ,then first item is a assigned in code .

When the programmer creates It, he/she must give the size of the array. This is the number of items that can be stored in the array. If the programmer wants to store more items then he/she must create a one. This is because the size of an array can not be changed.

When And Why It is required

In a variable you define one keyword and may be multiple values of the keyword .

Example

var alphabetFirst = a ;
var alphabetsecond = b ;

But you can do when a function need hundreds of variables with same data type value .

Example

var alphabetFirst = 0;
var alphabetFirst = 1;
var alphabetFirst = 2;
var alphabetFirst = 3;
var alphabetFirst = 4;
to
var alphabetThirty = 99;

In this situation your function or program is more complex ,not developer friendly , and consume more space on disk . An Array is the solution of this problem .

JavaScript Array Example

Following is the example JavaScript array  . In this example Alphabets is array name and a ,b,c,d,e,f  are the values .

var alphabets = ["a", "b", "c","d", "e", "f"];

Test This Example yourself

 Syntax

Syntax of array is vary according the language . Some of syntax examples are as follows

  • In c language
    int foo [5] = { 16, 2, 77, 40, 12071 }; 
  • In Visual basic
    Dim strCDRack(0 to 2) As String strCDRack(0) = "Deftones"
    strCDRack(1) = "Tool"
    strCDRack(2) = "Disturbed"