Answers for "typescript check if object has method"

1

check object has property in typescript

const hero = {
  name: 'Batman'
};

hero.hasOwnProperty('name');     // => true
hero.hasOwnProperty('realName'); // => false
Posted by: Guest on November-23-2020
4

typescript check if object has key

if ('key' in myObj)
Posted by: Guest on June-21-2020
1

check if object has method javascript

if(typeof myObj.prop2 === 'function') {
    alert("It's a function");
} else if (typeof myObj.prop2 === 'undefined') {
    alert("It's undefined");
} else {
    alert("It's neither undefined nor a function. It's a " + typeof myObj.prop2);
}
Posted by: Guest on June-25-2020

Code answers related to "typescript check if object has method"

Code answers related to "Javascript"

Browse Popular Code Answers by Language