Computer >> Computer tutorials >  >> Programming >> Javascript

Is there a way to print all methods of an object in JavaScript?


To get all the method, use Object.getOwnPropertyNames(). This returs all properties that belong to an object.

Example

You can try to run the following code to get all methods −

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <script>
         document.write("<br>"+Object.getOwnPropertyNames(Math).filter(function (p) {
            return typeof Math[p] === 'function';
         }));
      </script>
   </body>
</html>