Record collection understanding the exercise

but it is use to check property of the object and tracks is a property.
and what do you mean overwriting function parameter value?

why is it working when i write:(to acces or see if track exist in the object)

records[id].hasOwnProperty("tracks") 

but does not work when i write:

records[id][prop].hasOwnProperty("tracks")

??

Does the record have a track property or does the track property have a track property?

1 Like

record has the track property
you can see the code above if you want

I see the code… I’m asking you to think about what has the track property

what does it mean ?
how can a property have a property?
are you trying to say : tracks(name):“tracks”(value).then no

You are saying that the track property has a track property when you type

the object records has the tracks property

Nope. The records object has properties given by ID numbers. The individual record with ID number id has a "tracks" property.

does to the property of a nested object belong to the main object?

No. I’d double check your understanding of nested objects here:

i might be wrong …sorry in advance
but doesnt prop denotes tracks and artist.
so to access tracks i have to access it from prop
that means using:

records[id][prop].hasOwnProperty("tracks")

instead of using:

records[id].hasOwnProperty("tracks")

try to do console.log(records[id]) and console.log(records[id][prop])
which is the object?

1 Like

Did you review nested objects? The nested object has the property, not the property of the nested object.

Again, this is, literally, saying that the you want the tracks property of the tracks property.

it is saying records is not defined

i reviewed it.

still i dont get this
but a vague sollution is coming into my brain
is it because of the condition put that,

props==="tracks"

so the props is already equal to tracks and there is no property "artist’
and that’s why it is like testing if tracks has tracks property. is it the case?

You need to do that inside the function

console.log(records[id]);
output: {albumTitle: 'ABBA Gold', artist: 'ABBA'}
   undefined (i don't know why this came)

again,
console.log(records[id][prop])

output: ABBA
   undefined(no idea why this came)
  

so according to my observation,
the first block of code return the nested object id
whereas,
second block of code returned the tracks value
but, i don’t how they are related
please could you explain

Where did you do this? In a place where both records and id are defined?


// Setup
var recordCollection = {
2548: {
  albumTitle: 'Slippery When Wet',
  artist: 'Bon Jovi',
  tracks: ['Let It Rock', 'You Give Love a Bad Name']
},
2468: {
  albumTitle: '1999',
  artist: 'Prince',
  tracks: ['1999', 'Little Red Corvette']
},
1245: {
  artist: 'Robert Palmer',
  tracks: []
},
5439: {
  albumTitle: 'ABBA Gold'
}
};

// Only change code below this line
function updateRecords(records, id, prop, value) {
  console.log("records[id] =");
  console.log(records[id]);
  console.log(\n"prop =");
  console.log(prop);
  console.log("\nrecords[id][prop] =");
  console.log(records[id][prop]);
}

updateRecords(recordCollection, 5439, 'albumTitle', 'newTitle');

i have edited the post