Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM console.table() method

HTML DOM console.table() method

Console Object Console object

Example

Output a table on the console

console

.

table

(

[

"

Google

"

,

"

Runoob

"

,

"

Taobao

"

]

)

;

Try it »


Definition and Usage

The console.table() method is used to output table information on the console.

The first parameter is required, and its object type must be an object or an array; the corresponding data will be filled into the table.

Tip: During testing of this method, the console needs to be visible (press F12 in the browser to open the console).


Syntax



console.table(tabledata, tablecolumns)


Browser support

The numbers in the table indicate the first browser version that supports this method.

Method
console.table() Yes 12 34 Yes Yes

Parameter Description

Parameters Type Description
tabledata Array or Object Required. The data to fill into the table.
tablecolumns Array Optional. An array containing the names of the table header columns.

More examples

Example

Use an object as the output information:

console

.

table

(

{

name

:

"

Runoob Tutorial

"

,

site

:

"

www.runoob.com

"

}

)

;

Try it »

Example

Use an array of objects:

var

site1

=

{

name

:

"

Runoob

"

,

site

:

"

www.runoob.com

"

}

var

site2

=

{

name

:

"

Google

"

,

site

:

"

www.google.com

"

}

var

site3

=

{

name

:

"

Taobao

"

,

site

:

"

www.taobao.com

"

}

console

.

table

(

[

site1

,

site2

,

site3

]

)

;

Try it »

Example

Specify the table header title names; the parameter can only be the corresponding key names:

var

site1

=

{

name

:

"

Runoob

"

,

site

:

"

www.runoob.com

"

}

var

site2

=

{

name

:

"

Google

"

,

site

:

"

www.google.com

"

}

var

site3

=

{

name

:

"

Taobao

"

,

site

:

"

www.taobao.com

"

}

console

.

table

(

[

site1

,

site2

,

site3

]

,

[

"

site

"

]

)

;

Try it »

Console Object Console object