Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of Python's dir in Javascript

when I write Python code from the interpreter I can type dir() to have a list of names defined in the current scope. How can achieve to have the same information, programmatically, when I develop Javascript code from a browser using an interactive console like firebug, chrome console, etc?

like image 974
Paolo Avatar asked Apr 02 '11 14:04

Paolo


People also ask

What is Dir function in JavaScript?

dir() displays an interactive list of the properties of the specified JavaScript object. The output is presented as a hierarchical listing with disclosure triangles that let you see the contents of child objects. In other words, console.

What is the equivalent of a list in JavaScript?

The closest equivalent in all cases of what is passed to list() would be using the spread syntax from ES6. For older versions of JavaScript, you can use string. split('') for a character array.

What is python dir?

Python dir() Function The dir() function returns all properties and methods of the specified object, without the values. This function will return all the properties and methods, even built-in properties which are default for all object.

What is the equivalent of pass in JavaScript?

Python's pass mainly exists because in Python whitespace matters within a block. In Javascript, the equivalent would be putting nothing within the block, i.e. {} .


1 Answers

There is keys method in Object, for example:

Object.keys(object) 

But this return object's own properties and methods only.
To list all properties and methods of an object I know 2 possibilities:

  1. console.dir(object) method in firebug console for Firefox and
  2. dir(object) method in Google Chrome development tools.
like image 156
Andrey Avatar answered Sep 20 '22 06:09

Andrey