Record Collection Exercise - I cant figure it out!

hi! I have been stuck on this problem for days now! Im not even that far into my javascript training and I am stuck. Yikes!

Ok, this is what I have so far:

function updateRecords(id, prop, value) {

if (collection[id].hasOwnProperty(prop)) {

return collection;

} else {

collection[id].push(prop);
collection[id][prop] = “”;
collection[id][prop] = (value);
return collection;

I am trying to take the property prop and push it to the end of the object if the property is not currently there. I keep getting this error and I’m not sure why… "TypeError: Object doesn’t support property or method ‘push’

Thanks for your help!

Push is an array method. Collection is an object. If you get rid of that line altogether, it’ll probably work! :thumbsup:

Thank you Portable Stick. That definitely helped me understand how to use push! Now to make my code recognize when a variable is not being passed through a function or is null how to delete the prop.

I’ve tried:

function updateRecords(id, prop, value) {

if (value === “”){
delete connection[id][prop]
}

but I can’t seem to make the function recognize that the value is blank or null, even when id and prop is provided. Any hints would be greatly appreciated. I’ve been stuck on this problem for days!

Hint:
You should check if value is not truthy.

1 Like