Array

Updated: 10/02/2017 by Computer Hope

Array may refer to any of the following:

array1. When referring to programming, an array is a group of related data values (called elements) that are grouped together. All of the array elements must be the same data type. The examples below show how an array is defined and called in Perl and JavaScript.

Perl Array example

As you can see in the example below, our array is called "@numbers" and it contains a set of different numerical values that are spelled out.

my @numbers = ("one", "two", "three", "four", "five");
print "$numbers[0] and $number[1] equals 3";

The above Perl script prints the first two elements in this array by using $numbers[0] (0 always being the first number in programming) and $number[1], followed by the "equals 3" text (result in the box below).

one and two equals 3

Tip: When you call elements from an array by their element number, that number is referred to as a subscript.

JavaScript Array example

The below JavaScript array example utilizes the same array name and values as the Perl array example above.

function myFunc(){
var numbers = ["one", "two", "three", "four", "five"];
numbers.toString();
document.getElementById("example").innerHTML = numbers[0] + " and " + numbers[1] + " equals 3";
}

The above JavaScript code prints the first two elements in this array by using numbers[0] (0 always being the first value in a JavaScript array) and number[1], followed by the "equals 3" text (result in the box below).

one and two equals 3

The above JavaScript example assumes there is an HTML element with the ID of "example", such as <p id="example"> or <div id="example">, where the text is displayed.

Also, the function named "myFunc()" would need to be called and executed either as a page load event, such as <body onload="myFunction()">, a button click event, such as <button onclick="myFunction()">Try it</button>, or some other event on the page.

2. With computer drives, an array is two or more drives that are grouped together and act as one drive. For example, in a RAID array, a user may utilize multiple drives that mirror each other for redundancy to help protect the data contained on the drives.

Array of pointers, Hard drive terms, Programming terms, Pop, Push, Render array