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: