- In JavaScript, an array is an ordered collection of values that can store multiple data types (numbers, strings, objects, etc.) under a single variable name.
Zero-Indexed: The first element is always at index 0, the second at 1, and so on.
Array elements are enclosed within square brackets.
why we use array?
for example, if we have a list of items storing the fruit in single variables could look like this:
let fruit_1="mango";
let fruit_2="apple";
let fruit_3="orange";
Here, we have only 3 fruits so we can declare like this but, what if we have 300 fruits? It's very hard to do in this method right.
For this the solution is array.
An array can hold many values under a single name, and you can access the values by referring to an index number.
const fruits=['mango','apple','orange'];
So this method is easier than the above. Here we declared 3 fruits names under a single varible.
Example:
simple program to print failcount of the student,using array.
References:

Top comments (0)