Basic JavaScript - Manipulating Complex Objects

Hello. I am wondering where in the example it shows us how to "Add a new album to the myMusic array. We are tasked with adding a new album to the myMusic array, but this here below doesn’t really explain HOW to add it because the example did not show adding something new to an array. Where would I even start? I’m not trying to look for the answer – I just want to know how I would even figure this out.

"Sometimes you may want to store data in a flexible Data Structure. A JavaScript object is one way to handle flexible data. They allow for arbitrary combinations of strings, numbers, booleans, arrays, functions, and objects.

Here’s an example of a complex data structure:

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

This is an array which contains one object inside. The object has various pieces of metadata about an album. It also has a nested formats array. If you want to add more album records, you can do this by adding records to the top level array. Objects hold data in a property, which has a key-value format. In the example above, "artist": "Daft Punk" is a property that has a key of artist and a value of Daft Punk.

Note: You will need to place a comma after every object in the array, unless it is the last object in the array"

const myMusic = [
{
  "artist": "Billy Joel",
  "title": "Piano Man",
  "release_year": 1973,
  "formats": [
    "CD",
    "8T",
    "LP"
  ],
  "gold": true
}
];
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Manipulating Complex Objects

Link to the challenge:

Here is an example record.

You need a second record object in the same array that has the fields artist, title, release_year, formats.

As you move through the curriculum, these challenges move away from ‘here is the exact syntax, copy it’ to ‘here is a task you need to do with previous content’.

In this case, you have made objects before and you have made arrays before. This challenge wants you to make an object inside of the array.

Here is my code

  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [
      "CD",
      "8T",
      "LP"
    ],
    "gold": true
  },
  "artist": "James Hetfeld",
  "title": "Vocalist",
  "release_year": 1993,
  "formats": [
    "CD",
    "8T",
    "LP"
  ]
];```

This is not a complete object - you don’t have any {} around it

Oh wow. Thanks for your assistance

1 Like

You’re a bit early in your attempt to look at techniques, to do this.
The question just expects you to type in the {key: value} pairs

Just check out the structure of things a bit. You need a keen eye to follow the bracket pairs

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.