javascript - A JS function not recognising an object's property -
this question has answer here:
i create js function takes 2 arguments: object , property. if object has given property, function should remove object, , return true.
this far i've got, keeps returning false on test cases. believe because 'obj.prop' part not catching - not sure why.
any appreciated!
function removeproperty(obj, prop) { if ( obj.prop ) { delete obj.prop; return true; } else { return false; } }
change .you passing variable not direct name of property
function removeproperty(obj, prop) { if (obj[prop]) { delete obj[prop]; return true; } else { return false; } }
Comments
Post a Comment