Javascript Arrays

Javascript Arrays

ยท

2 min read

A detailed explanation of JavaScript Arrays with handwritten notes.

TABLE OF CONTENTS

  1. What is an Array?
  2. Creating an Array
  3. Accessing an Array
  4. Modifying an Array
  5. Some of the basic array methods
  6. Reference types & Equality testing of arrays

1. What is an Array?

๐ŸŒ  An array is an object where we can store multiple values at once. These values can be of any type:- number, boolean, string, falsy values, etc. These values can be of the same type or mixed type. Arrays are declared using [] (square brackets).

IMG_20220924_070935.jpg

2. Creating an Array

๐ŸŒ  As I told you in the previous section about how arrays can be of any type, below is a detailed explanation of how to create one:

Untitled 5.jpg

3. Accessing an Array

๐ŸŒ  Arrays can be accessed by their index number. Each element has a corresponding index (starting from 0). We just have to put the array name with the index number arrayname[index-number].

Untitled 7.jpg

NOTE:- Array length is always one greater than the index number. If the index number is 10 (starting from 0), the length will be 11 (length count from 1).

4. Modifying an Array

๐ŸŒ  Suppose, I made a mistake while declaring the items in an array. And now I have to change and correct the values/value inside an array. This is what we have to do ๐Ÿ‘‡

Untitled 8.jpg

5. Some of the basic array methods

๐ŸŒ  Some of the array methods in javascript are :

Untitled 9.jpg

There are many more other than these methods. For a detailed explanation of each and every array method follow this link: MDN Array Methods.

6. Reference types & Equality testing of arrays

๐ŸŒ  We know how double and triple equals work, right? But this is not the same case all the time, at least not for arrays. Below is a detailed explanation of why...

Untitled 10.jpg

Untitled 11.jpg

That's it for now. ๐Ÿ˜‡

I hope I have helped you to understand the concept of Javascript Arrays through my blog. Though this is my first blog, I will be writing about HTML, CSS, TailwindCSS, and JS from now on.

Tweeter handle: Sneha Purkayastha

ย