Arrays

For absolute beginners.

Paige Miles
2 min readApr 25, 2021

What is an array?

An array is a collection of data grouped and stored in a contiguous block of memory. An array can be made of any data type: string, boolean, number, an array of arrays, etc.

Advantages of arrays

The main advantage of arrays is the ability to look up any value in an array based on its index with O(1) time complexity.

For example:

const array = ["a", "b", "c"]// The value at array[0] is "a"
// The value at array[1] is "b"
// The value at array[2] is "c"

NOTE: indexing starts at 0.

Disadvantages of arrays

Elements cannot be added to an array when that original, fixed array is full.

ENTER: Dynamically Resizing Array

A dynamically resizing array is still an array in all the ways described above; however, when you append to a full array, a new array of double the original array size is created, i.e., if the original array was 2 elements long, the new array will be 4 elements in size.

The data from the original, full array will be copied to the new array. The new value (the triggered all this nonsense) will be appended to the new, longer array. The original array is deleted.

Now that I’ve used the word array more times than anyone has a right to do…wtf are they used for?

Useful applications of arrays

  • Storing data that belong together.
  • Storing ordered data.
  • Storing data to refer back to later.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response