Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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);
}
Comment

Check If Object Contains A Function


 
		 const res = {a:"aaa", b:function(){console.log("b")}};
	 
	 console.log(typeof res.b == "function");
	 /*true, notice it is b and not b()*/

Comment

PREVIOUS NEXT
Code Example
Javascript :: npm error Could not resolve dependency peer react@"^18.0.0" from react-test-renderer@18.0.0 
Javascript :: how to export a variable in javascript 
Javascript :: jquery set span text by id 
Javascript :: counts the duplicates in an array using for loop 
Javascript :: pretty alerts js 
Javascript :: adjacent elements product javascript 
Javascript :: print random string from an array to screen in javascript 
Javascript :: javascript async function 
Javascript :: jest input value 
Javascript :: string uppercase 
Javascript :: force click btn using jquery 
Javascript :: store input into array javascript 
Javascript :: how to change background color on scroll 
Javascript :: make text lowercase javascript 
Javascript :: nginx react router 
Javascript :: click a link with javascript 
Javascript :: how set defualt image for dropify 
Javascript :: select in react js 
Javascript :: get top window url from iframe 
Javascript :: cookie clicker hack extension 
Javascript :: get element by id jqueryt 
Javascript :: is function javascript 
Javascript :: react native modal close when click outside 
Javascript :: javascript queryselector 
Javascript :: javascript get last object in foreach loop 
Javascript :: angular list contains property 
Javascript :: javasript document referrer 
Javascript :: uppercase javascript using function 
Javascript :: js convert string array to number array 
Javascript :: how to poll efficiently in javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =