Skip to main content

Arrays, explained.

Published 2021/09/09 12:00

What are ARRAYS in programming?

Let's explain.

Arrays in programming are essentially ways of storing lists of things in a program or app.

The way to store these lists, will depend on the programming language you use.

So, suppose you need to make a list of things to buy.

What you would usually do is take out a piece of paper from a notebook and write everything you need to buy.

You decide there's a better way. Make a program on your computer instead!

So how would you store this list?

We've talked about variables before. Basically a way to store things that would be used later.

More on variables here

Same way we store text or numbers, we can store lists of text or numbers.

In our case, we want to store a list of items to buy. That means we need a text list!

In Javascript, for example, this is how we store lists:

let stuffToBuy = ["Milk", "Orange juice", "A laptop for coding"]

In Python, it's similar:

stuffToBuy = ["Milk", "Orange juice", "A laptop for coding"]

Now you can do stuff like, select a specific item in the list, depending on its position:

stuffToBuy[1]

// ==> Orange juice

Add (push) stuff to your list:

stuffToBuy.push("Cheese")

Check how large a list is:

let stuffToBuy = ["Milk", "Orange juice", "A laptop for coding"]
stuffToBuy.length
// 3

Or go through each and every element in the list and do something specific with it.

This is called a "loop" and it's something we'll talk about in another thread, so watch this space.

Thank you for reading!

Dev, Explained (43 part series)

  1. Javascript Scopes, explained.
  2. Javascript Promises, explained.
  3. Accessibility, explained.
  4. React, explained
  5. Should I use forEach() or map()?
  6. Should I use Flexbox or CSS Grid?
  7. Docker, explained.
  8. Unit testing, explained
  9. Git, explained.
  10. Typescript, explained.
  11. async/await, explained.
  12. The DOM, explained.
  13. Regular expressions, explained
  14. GraphQL, explained.
  15. Vue, explained.
  16. Svelte, explained.
  17. API, explained.
  18. Javascript Hoisting, explained.
  19. Immediately Invoked Function Expressions (IIFE), explained.
  20. ARIA roles, explained.
  21. Test-driven Development, explained.
  22. ARIA live regions, explained.
  23. aria-label in accessibility, explained.
  24. Type coercion in Javascript, explained.
  25. Variables, explained.
  26. if statements, explained.
  27. Arrays, explained.
  28. Currying in Javascript, explained.
  29. Memoization, explained.
  30. For loops, explained.
  31. Javascript Prototypes, explained.
  32. React Hooks, explained.
  33. Graph databases, explained.
  34. MongoDB, explained.
  35. Serverless, explained.
  36. Javascript Callback functions, explained.
  37. HTML, explained.
  38. CSS, explained.
  39. Responsive design, explained.
  40. Javascript, explained.
  41. The CSS Box Model, explained.
  42. CSS Flexbox, explained.
  43. CSS Grid, explained.
2022 Savvas Stephanides
Buy me a coffee
Some icons from Freepik