Tell us what’s happening:
Hi there, first of all, please spare your judgement, I’m completely new and just trying to understand what’s happening here:
Question - Is this the part of the code that adds a new property to the object if the property doesn’t yet exist?
else if (prop !== “tracks” && value !== “”) {records[id][prop] = value;
Here’s my complete code (after the predefined array) for reference:
function updateRecords(records, id, prop, value) {
if (value === "") {
delete records[id][prop];
} else if (prop !== "tracks" && value !== "") {
records[id][prop] = value;
} else if (prop === "tracks" && value !== "" && !Object.hasOwn(records[id], "tracks")) {
records[id]["tracks"] = [value];
} else if (prop === "tracks" && value !== "") {
records[id][prop].push(value);
}
return records [id]
}