Working With Arrays Part 2 | Tiffany R. White Blog

Working With Arrays Part 2

Reading time: 1 min


What is an array?

You use an array to store data. You can initialize an empty array and then store data in it as well. But that is beyond the scope of this post.

There are 4 types of arrays in JavaScript:

  • Homogeneous
  • Heterogeneous
  • Multidimensional
  • Jagged (or ragged)

Homogeneous Arrays

Homogeneous arrays only store one data type. It can be any data type but it can only contain data of that particular type. For example:

// An array of ints
var array = [45, 37, 69, 90];

// An array of Boolean values
var array = [true, false];

// An array of Strings
var array = ["Mom", "Rick", "orange"];

Hetergeneous Arrays…

Can contain a mixture of data types. For example:

var anArray = ["peaches", 9, "cream", false];

Multidimensional Arrays

A multidimensional array is just an array of arrays. Think of them as nested arrays. For example:

var myArray = [["Mom", 71, "Me", 36], ["John", 40], [true]];

Jagged Arrays

A jagged array is an array that looks like a multidimesional array but does not have a particular order. They look like this:

var myArray = [
     ["Jerri", 70, "Tiffany"],
     ["John", false],

An Empty Array

Is an array with nothing in it. For example:

var anArray = [];

This is useful for loops and adding data later to your program.

These are the types of arrays in JavaScript. I will cover arrays in Java as well.


No Ads. No Sponsored Content. Ever.

I've decided that I no longer want to have sponsored posts on this blog. I also, though as tempting as it may sound, don't want ads; even if I got big enough for Carbon ads I don't want them. I want to post free, engaging content for beginning/junior devs. This means that I won't have Setapp posts or affiliates on this blog, though I will keep them on the Uses page. If you enjoy the content, buy me a coffee. Just click the button below.

Coffee Buy me a coffeeBuy me a coffee

Webmentions 0

No webmentions were found.