Home > Web Front-end > JS Tutorial > body text

Introduction to the console.dir() function in JavaScript

高洛峰
Release: 2017-02-03 14:47:48
Original
2073 people have browsed it

When debugging a JavaScript program, sometimes you need to dump the detailed information of certain objects. This work can be accomplished by manually writing JavaScript code: looping over the properties of the object and printing out each property value looped through; it can be seen that this process is relatively cumbersome. On browsers with debugging tools, this work can be easily accomplished through the console.dir() statement.

Usage of console.dir()

Using console.dir() is very simple, just pass the object that needs to be dumped directly into the statement. For example, the following example:

function cat(name, age, score){
    this.name = name;
    this.age = age;
    this.score = score;
}
var c = new cat("miao", 2, [6,8,7]);
console.dir(c);
Copy after login

By using console.dir(), the newly created cat object information is dumped. The display result in the Firebug console is:

Introduction to the console.dir() function in JavaScript

If what needs to be dumped is a DOM object, then using console.dirxml() will get a better display effect.

Browser support

console.dir() and console.dirxml() are better supported on browsers with debugging tools, and all major browsers support this function.

For more articles related to the introduction of the console.dir() function in JavaScript, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!