2

I'd like to introspect methods available to me on an array object

> console.log(Array.prototype)
[]
undefined
> console.log(Array.prototype.push)
[Function: push]

How can i see or log all properties / methods available on an objects prototype?

Mohammad Usman
  • 37,952
  • 20
  • 92
  • 95
random-forest-cat
  • 33,652
  • 11
  • 120
  • 99
  • [Array.prototype](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype) – Bash Jun 17 '19 at 18:16
  • 1
    Possible duplicate of [How to display all methods of an object?](https://stackoverflow.com/questions/2257993/how-to-display-all-methods-of-an-object) – Shidersz Jun 17 '19 at 18:25

1 Answers1

6

You can use .getOwnPropertyNames() which return an array of all property names (including non-enumerable properties):

const PrintAll = obj => console.log(Object.getOwnPropertyNames(obj));

PrintAll(Array.prototype);
.as-console-wrapper { max-height: 100% !important; top: 0; }
Mohammad Usman
  • 37,952
  • 20
  • 92
  • 95