+ 2

Is there really any equivalent of the python's function dir() in js?

Python's dir() function reveals all the properties of an object and returns a list. This works for both functions and classes(objects). I found out that js has a console.dir() function similar to python's dir(). But this only works for objects. Not for functions.

4th Feb 2020, 3:51 PM
Ishmam
Ishmam - avatar
5 Réponses
+ 3
reversed ( ) you can use Object.getOwnPropertyNames(obj) and Object.getOwnPropertyNames(obj.prototype) For example to get all the Array properties Object.getOwnPropertyNames(Array) or Object.getOwnPropertyNames(Array.protype) for Number or String: Object.getOwnPropertyNames(String.prototype) Object.getOwnPropertyNames(Number.prototype) and it works for any function too.
5th Feb 2020, 1:23 AM
Calviղ
Calviղ - avatar
+ 2
Use Object.keys(obj) to get all the properties of object obj.
4th Feb 2020, 4:11 PM
Calviղ
Calviղ - avatar
+ 2
Thanks Calviղ for the help! 😄
5th Feb 2020, 3:53 AM
Ishmam
Ishmam - avatar
+ 1
Calviղ does it work for Number or String or any other function?
4th Feb 2020, 4:37 PM
Ishmam
Ishmam - avatar
0
help()
5th Feb 2020, 9:39 AM
Konala Teja Sri