Manipulating Complex Objects-help

What’s wrong here.Manipulating Complex Object?

Your code so far

var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  }
  // Add record here
  var myMusic = [
  {
    "artist" : "Daddy Yankee",
    "title" : "Barrio Fino",
    "release_year" : 2004,
    "formats" : [ 
      "CS", 
      "8T", 
      "LP" 
]
  }
];

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299.

Link to the challenge:
https://www.freecodecamp.org/challenges/manipulating-complex-objects

still in stuck
var otherMusic = [
{
“artist” : “Linkin Park”,
“title” : “Meteora”,
“release_year” : 2004,
“formats” : [
“CS”,
“8T”,
“LP”, ]

}
];

Hi zsinyi2,

It is possible create a new array, but you need add a index for new album . Remember that the myAlbum “Billy Joel” is on index [0]. So we need add a second array for the first array, creating a multidimensional Array. There are two ways to get it. See lessons Access Multi-Dimensional Arrays With Indexes and Manipulate Arrays With push().

//The fisrt way to achieve it is using index. Create a new array, in this case below I call it var myNewAlbum and after apply that new array as a new index for array myAlbum.

var myNewAlbum =
{
“artist”: “Skank”,
“title”: “Jack Tequila”,
“release_year”: 1994,
“formats”: [
“CS”, “8T”, “LP”]
};
// Applying index:
myMusic[1] = myNewAlbum;

//The second way to achieve it is keeping the var my NewAlbum and to replacing the last line from code above using .push().

var myNewAlbum =
{
“artist”: “Skank”,
“title”: “Jack Tequila”,
“release_year”: 1994,
“formats”: [
“CS”, “8T”, “LP”]
};

//Now, just replace the last line using .push() to add the new array for myMusic like that:
myMusic.push(myNewAlbum);

Test both yourself. :wink:

//Data structure is pretty important concept in computing. Check other explanation sources about Data Structure, like wikipedia. I reaaly hope that be a help.

Yes randelldawson. I checked again and the code was wrong due sintaxe. I was using brackets [ ] , to start a new Array, but It was wrong , because bracket refer to external and first array. The new array need start and finish with braces { }.

I put a new answer using two solutions and both work well:

//below using .push();
var myNewAlbum =
{
“artist”: “Skank”,
“title”: “Jack Tequila”,
“release_year”: 1994,
“formats”: [
“CS”, “8T”, “LP”]
};

myMusic.push(myNewAlbum);

//Below using a new index, just replacing the last line above:
myMusic[1] = myNewAlbum;

1 Like