Objects inside arrays

what is the use of array that contains objects inside it? How can I access individual objects and use its data?
for example this objects, how can I use its data for anything?

var myMusic = [
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "LP" ],
    "gold": true
               "arits":"bob dylan",
               "album":"free willing",

You can access these objects the same as you would with “normal” arrays:

let first_object = myMusic[0];

And then you can access its properties like a normal object:

let first_artist = first_object.artist; 
// same as:
let first_artist = first_object["artist"];
// and:
let first_artist = myMusic[0].artist;

console.log(first_artist);   // Billy Joel
1 Like

I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard.


like this is ok?

thanks I got it! what the “let” means?

Nope, you need backticks, see the link in @ArielLeslie’s post.

let is ES6 syntax, it is almost the same as var.

1 Like