JS Record collection

I’ve been stuck on this for days too. Please help me figure out what I’m doing wrong.

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

let checkProp= id.hasOwnProperty(“tracks”);
let emptyArray=;

if (value!==“”)
{
if (prop!==“tracks”)
{
records[id][prop]=value;
}
else if ((prop===“tracks”) && (checkProp===false))
{
records[id][prop]=emptyArray;
emptyArray.push(value);
}
else if (prop===“tracks”)
{
records[id][prop].push(value);
}

}
else if (value===“”)
{
delete records[id][prop];
}
return records;
}

The output is:

updateRecords(recordCollection, 2468, “tracks”, “Free”)
tracks should have the string 1999 as the first element.

Check again which of these cases is used and then investigate why.
What methods did you already use to find the error?

To fix this error, i think it’s directly related to else if(prop===“tracks”).
I’ve tried rewriting the code and this was the best version so far. What happens is the tracks array gets rid of the original list. and replaces it with the new value only.

What does this do. I don’t think it does what you think

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.