javascript - A JS function not recognising an object's property -


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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -