Log all methods on array prototype

Viewed 288

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?

1 Answers

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

Related