Home > Web Front-end > JS Tutorial > Debugging javascript_javascript tips with console.table()

Debugging javascript_javascript tips with console.table()

WBOY
Release: 2016-05-16 16:37:24
Original
1120 people have browsed it

Use CONSOLE.LOG() to display arrays

Imagine you constructed the following array
var languages ​​= [
{ name: "JavaScript", fileExtension: ".js" },
{ name: "TypeScript", fileExtension: ".ts" },
{ name: "CoffeeScript", fileExtension: ".coffee" }
];

<code>console.log(languages);</code>
Copy after login

console.log() will display the array like this

This kind of display is very useful for development, but I find it a bit cumbersome to manually click on each Object. At this time, I think console.table() is a bit interesting.

Use CONSOLE.TABLE() to display arrays

Now let’s try using console.table():

Is it very small?

Of course, console.table() is more suitable. Flat data is listed in table format and displayed more perfectly. Otherwise, if each array element has a different structure, many grids in your table will be undefined.

Use CONSOLE.TABLE() to display object

Another feature of console.table() is to display objects.

<code>var languages = {<br>csharp: { name: "C#", paradigm: "object-oriented" },<br>fsharp: { name: "F#", paradigm: "functional" }<br>};</code>
Copy after login
<code>console.table(languages);</code>
Copy after login

Properly.

Filtering function of CONSOLE.TABLE()

If you want to limit console.table() to display a certain column, you can pass in a keyword list in the parameter as follows:
// Multiple property keys
console.table(languages, ["name", "paradigm"]);

If you want to access a property, one parameter is enough,

<code>// A single property 
keyconsole.table(languages, "name");</code>
Copy after login

I once thought that I already understood most of the functions of the Chrome Developer Tools, but now I am obviously wrong. If you have nothing to do, go check out the Chrome DevTools documentation!

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