Frontend Weekly
Published in

Frontend Weekly

JavaScript Objects Quickly Explained

You know about Arrays right? An array is an ordered collection of data. Similarly, an object is an unordered collection of data.

Let’s look at an array:

So I have this array (or ordered list called justiceLeague with 7 members in in.

An array is an ordered list, where:

The first item is always placed at zero 0 because, binary!

So if I have to call the first member of the justice league, I will have to call justiceLeague[0]

Okay, now that you get an overview of Arrays, let’s talk about JavaScript objects.

In JavaScript, objects are typed inside curly braces {}

They are just like arrays, but they are not an ordered list.

Let’s have a look:

So with this format, there is not first or last member, they are all designated with their respective key ‘s.

So if I were to call the boss of this object, I would do so like this: crimeSyndicate['boss'] which would return the value ‘Superwoman’.

Just like arrays, you can have sub properties of an object:

So if I do this: superHero['super']['power'] I will get an output of ‘Super Speed’.

There is another neat way to call this, superHero.super.power will output the same result, this is called a dot notation.

Objects can also have functions as its members, I talked about it in my next post: Creating The Infinity Gauntlet of Thanos with JavaScript Objects.

Found this post helpful? Please give it a CLAP!

Want to read more about JavaScript and Node JS? Check out my blog tamalweb.com/blog

--

--

It's really hard to keep up with all the front-end development news out there. Let us help you. We hand-pick interesting articles related to front-end development. You can also subscribe to our weekly newsletter at http://frontendweekly.co

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tamal Chowdhury

Software Engineer & Developer Advocate. Looking for my next role in tech. Resume 👇 https://tamalchowdhury.com