So you have learned the basics of JavaScript and want to move on to learning Data Structures. The motivation for learning/understanding Data Structures can vary since few of us, want to learn to improve our skills, few of us want to learn to get a developer job, and few of us want to learn because well, it seems exciting. Whatever the motivation might be, learning and understanding Data Structures can be a tedious and frustrating task if one does not understand why one should use data structures and when to use them.

This article deals with the when to use them part. In this article, we will learn about Arrays and Objects. We will try to understand when to choose one Data Structure over another by using the Big O notation.

Arrays

One of the most widely used data structures is arrays (also called lists in few languages). Data inside an array gets structured in an orderly fashion i.e the first element inside an array gets stored at index 0, the second element at index 1, and so on. JavaScript provides us with some built-in data structures and an array is one of them.

In JavaScript, the easiest way to define an array is:

let arr = [ ];

The above line of code creates a dynamic array(unknown length). To get the gist of how elements of an array get stored inside memory, let’s take a look at an example:

let arr = ["John", "Lily", "William", "Cindy"];

In the above example, we are creating an array containing names. The names inside the memory get stored like this:

How arrays get stored in the memoryHow arrays get stored in the memory

To understand how an array works, let us perform a few operations:

#javascript #objects #arrays #web-development

Comparing Data Structures in JavaScript (Arrays vs Objects)
1.15 GEEK