Javascript query manipulating objects

can anyone tell me why the first code snippet uses square curly bracket inside square bracket, and why the second snippet does not? The first is from Javascript manipulating complex objects and the second is from the next challenge accessing nested objects.

First snippet:

var ourMusic = [ { "artist": "Daft Punk", "title": "Homework", "release_year": 1997, "formats": [ "CD", "Cassette", "LP" ], "gold": true } ];

Second snippet:

var ourStorage = {
  "desk": {
    "drawer": "stapler"
  },
  "cabinet": {
    "top drawer": { 
      "folder1": "a file",
      "folder2": "secrets"
    },
    "bottom drawer": "soda"
  }
};
ourStorage.cabinet["top drawer"].folder2;  // "secrets"
ourStorage.desk.drawer; // "stapler"

The first snippet, is there a reason? Maybe it because an array prototypical method can easily be used on ourMusic.

Second snippet, why… Maybe it’s because of easy accessibility. Object is easily accessible than an array.

I hope it helps.

The first one is an array which has it’s value as an object.
The second is an object, which also has it entries as objects.

Thanks. That helps yes.

One is an array (a collection of things, normally of the same type in order) and one is an object (a collection of key: value things, not in order). They’re just two different types of things

Array:

[1, 2, 3]

Object:

{ foo: 1, bar: 2 }

2 Likes