A problem arises..
Suppose you have the marks of the 6 tests recently conducted in your school and would like to store them in a program to perform operations on them like sorting, calculating percentages, the mean, the median etc. What will you use to store the data? Six separate variables for storing the marks or something more interesting?
Let's consider the former. Yes you can create six different variables to hold the marks of the six tests but doing so may not be an efficient way to carry out the aformentioned tasks. In fact some tasks may be totally impractical if done using various variables.
For example consider the problem of sorting the numbers. How can you determine the least of the six variables, then the least of the rest five, then four and so on. What if you had 100 test scores and not just 6? If you think on it for a while you'll soon realise that separate variables aren't the solution to even simple cases of this problem in any way.
So what else can we use that's more interesting and efficient than this monotonous approach. Well the answer is very simple - an array!
What are arrays?
Let's start by formally defining what an array is and then understand on the key terms step-by-step.
An array is much like a list of values stored in memory in a structured way.
The actual values within an array are called elements whereas their respective positions are called indexes.
Indexes start at 0. This means the first value in an array is at index 0, the second one is at index 1 and so on.
Arrays can be represented using square brackets
Following is an example, demonstrating an array of the marks you scored in the 6 tests.
// index 0 1 2 3 4 5 var marks = [37, 68, 95, 66, 71, 39]; // your marks in the six tests
But why arrays?
As you just saw above, the problem of storing your marks, with the ability to perform functions on them, can easily be solved by an array.
An array not just stores data but also gives a great vector of features that can be used on that data. You can sort the data, like numbers, in ascending order or descending order. You can search for data, like names, in an array and see if a given value exists. You can replace data, add data, remove data and do so much more.
All of these functionalities can't be provided, in any way, by separate variables storing each of the bit of data individually.