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

JavascriptWeb DevelopmentFront End Technology

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>
raja
Published on 03-Feb-2018 15:31:54
Advertisements