Manipulating Complex Objects | What are they trying to teach us via this challenge?

Tell us what’s happening:

Hey, I passed the challenge but I don’t get what happened and what is the point of it. Somebody can explain it please? :slight_smile: I have C# background but damn JS seems harder then other programming languages =D.

My code so far


var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CD",
      "8T",
      "LP"
    ],
    "gold": true
  },

  {
    "artist": "George",
    "title": "Yeah! lol",
    "release_year": 2016,
    "formats": 
    [
      "CS",
      "Hat",
      "DL"
    ]
  }
  // Add record here
];

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects

In an ideal world, you will always works with data that is “flat”, this means only “one level deep”
es:

const book = {
  title: "Harry Potter and The Philosopher's Stone"
}

This way, if I want to print the title all i need to access it is book.title.

The reality however is that you will have to work with more complex data than this, usually with information nested in some other data.
For example, in an imaginary Harry Potter API it’s more likely that the response would be an array of Book objects:

const books = [
{ title: "Harry Potter and The Philosopher's Stone" },
{ title: "Harry Potter and The Chamber of Secrets" },
/* etc etc */
{ title: "Harry Potter and The Deathly Hallows" },
]

This means that this time if I want to print the title, I have to access it nested in the array first:

books[1].title // "Harry Potter and The Chamber of Secrets"

The aim of this lesson then is probably a soft introduction to working with complex data.

If you want to see how a real API replies, you can try Github API, simply paste the following URL in your browser, you’ll see a typical JSON response.
For example to see a users starred repos try pasting in your url tab:

https://api.github.com/users/:username/starred

You can try with my username if you want to see my starred repos:

https://api.github.com/users/marmiz/starred

Hope this helps :+1:

2 Likes

Crystal clear.

Thanks a lot!