I am currently wondering if the following piece of Javascript code could be simplified? I would like to return the correct {},[],""
without having to pass a type as argument. Is it possible?
function getObjectProperty(object,field,type){
switch (type){
case "Array":
return object && object.hasOwnProperty(field) ? object[field] : [];
break;
case "String":
return object && object.hasOwnProperty(field) ? object[field] : "";
break;
case "Object":
return object && object.hasOwnProperty(field) ? object[field] : {};
break;
case "Boolean":
return object && object.hasOwnProperty(field) ? object[field] : false;
break;
}
}