Objects inside arrays

Objects inside arrays
0

#1

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": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  },
           {
               "arits":"bob dylan",
               "album":"free willing",
               release_year:1964,
               formats:["cd","record","kasets"]
               
           }
];

#2

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

#3

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.


#4

like this is ok?


#5

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


#6

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

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