Dont know what i did wrong with record collection

Hello i have problem with record collection the problem is that i dont know where is my mistake i think that i have done eveything right but i still get errors so please read my code and give me your thoughts, thank you!

function updateRecords(records, id, prop, value) {

  if(prop != "tracks" && value.length!==0){

    records.id.prop=value;}

  else if( prop=="tracks" && records.id.hasOwnProperty("tracks")===false){

   var arr=[];

   arr=value;}

  else if(prop=="tracks" && value.length !==0){

    records.id.prop.push(value);}

  else if(value.length==0){

    delete records.id.prop;}

  return records;

}

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

To start, you can’t access the properties with dot notation. id and prop are variables that hold the names of the properties that you want.

thank you this is my first time posting in the forum i will keep that in mind for the next time

This is where you really start learning three difference between “dot notation” (like student.name) and bracket notation (like library[isbn], where isbn might contagion a unique id string for a book).

thank you that was my mistake !

1 Like