Member-only story

Object-Oriented JavaScript — Arrays and Conditionals

John Au-Yeung
3 min readSep 15, 2020

--

Photo by Jen Theodore on Unsplash

JavaScript is partly an object-oriented language.

To learn JavaScript, we got to learn the object-oriented parts of JavaScript.

In this article, we’ll look at arrays and conditionals.

Arrays

An array is a sequence of values.

It’s an object type.

It can have anything in them, including primitive values and objects.

We can define an empty array with:

let a = [];

And we can put values in them by writing:

let a = [1, 2, 3];

Array index is the position of the item. Arrays start with 0 as its index.

So the first item has index 0.

We can access any element using square brackets:

a[0];

then we get 1.

Adding/Updating Array Elements

We can add a value to an array by assigning a value to it.

For instance, we can write:

a[2] = 'foo';

Then we get:

[1, 2, 'foo'];

--

--

No responses yet