freeCodeCamp/guide/english/certifications/javascript-algorithms-and-d.../basic-javascript/manipulating-complex-objects/index.md

1.7 KiB
Raw Blame History

title
Manipulating Complex Objects

Manipulating Complex Objects

Heres the example:

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

Heres a solution: After string // Add record here we add new album to the myMusic. You need to start from ,. And you can just copy already created album:

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

and paste after ,:

  // Add record here
  ,
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CD",
      "8T",
      "LP"
    ],
    "gold": true
  }
];

Now, you can change values your album:

  // Add record here
  ,
  {
    "artist": "Deep Purple",
    "title": "Smoke on the water",
    "release_year": 1976,
    "formats": [ 
      "CD",
      "8T",
      "LP"
    ],
    "gold": true
  }
];

Heres a full solution:

var myMusic = [
 {
   "artist": "Billy Joel",
   "title": "Piano Man",
   "release_year": 1973,
   "formats": [ 
     "CD",
     "8T",
     "LP"
   ],
   "gold": true
 },
 // Add record here
 {
   "artist": "Deep Purple",
   "title": "Smoke on the water",
   "release_year": 1976,
   "formats": [ 
     "CD",
     "8T",
     "LP"
   ],
 }
];