Types of Array
Explore how arrays are classified by size and dimensions in JavaScript. Understand the differences between static and dynamic arrays and learn to work with one-dimensional, two-dimensional, and multidimensional arrays to represent complex data.
In the previous lesson, we learned what arrays are, how they are indexed, and how they are stored in memory. In this lesson, we will look at how arrays are classified, both by their size and by their dimensions.
Classification of arrays
Arrays can be classified in two ways:
By their size
By their dimensions
Classification by size
Based on their size, arrays can be classified into two types: static and dynamic. Each differs in how memory is allocated and how much flexibility the array offers. Let’s look at each one in turn.
Static arrays
A static array has a fixed size that is set at the time it is created. The number of elements is fixed at initialization and does not change during program execution.
Think of it like a printed scorecard with exactly ten rows. If we bowl an eleventh game, there is no room to record it. We would have to start a new, larger scorecard entirely if we want to keep a record of the eleventh game. The original card cannot grow.
This approach is simple and memory-efficient. The computer allocates exactly as much space as ...