What are arrays and why are they useful

An array is a way or storing similar type of data for later access.
An array is a user-defined object and they are accessed differently that other objects are accessed.

An array uses a single variable name to store multiple values.
They can be accessed using an index number or in the case of the associative arrays using just a string.

For example if you want to print the name of all students of a class you can use arrays.
You could use regular variables to store the names of the students then type into a document.write() method the names of the variables, but that will take a very long time.
Instead you could use an array to store the students’ name and access it easily using a loop.

Leave a Reply