01 April 23
Frontend developmentin Javascript?
console.dir()
Method in JavaScriptThe console.dir()
method in JavaScript is used to display an interactive list of the properties of a specified JavaScript object. It is similar to console.log()
, but instead of logging the object in a stringified form, it displays the object's properties in an interactive list. This list can be expanded and collapsed, allowing the user to inspect the object's properties in more detail.
The syntax for the console.dir()
method is as follows:
console.dir(object);
Where object
is the object whose properties you wish to inspect.
Let's look at an example of how to use the console.dir()
method.
const person = { name: 'John Doe', age: 30, address: { street: '123 Main St', city: 'New York', state: 'NY' } }; console.dir(person);
When this code is executed, the following output will be displayed in the console:
As you can see, the console.dir()
method displays an interactive list of the properties of the person
object. This list can be expanded and collapsed, allowing the user to inspect the object's properties in more detail.
Frontend development