将表列数据显示为表格。

This function takes one mandatory argument data , which must be an array or an object, and one additional optional parameter columns .

It logs data as a table. Each element in the array (or enumerable property if data is an object) will be a row in the table.

The first column in the table will be labeled (index) 。若 data is an array, then its values will be the array indices. If data is an object, then its values will be the property names. Note that (in Firefox) console.table is limited to displaying 1000 rows (first row is the labeled index).

注意: 此特征可用于 Web 工作者 .

Collections of primitive types

data argument may be an array or an object.

// an array of strings
console.table(["apples", "oranges", "bananas"]);
					
// an object whose properties are strings
function Person(firstName, lastName) {
  this.firstName = firstName;
  this.lastName = lastName;
}
var me = new Person("John", "Smith");
console.table(me);
					

Collections of compound types

If the elements in the array, or properties in the object, are themselves arrays or objects, then their elements or properties are enumerated in the row, one per column:

// an array of arrays
var people = [["John", "Smith"], ["Jane", "Doe"], ["Emily", "Jones"]]
console.table(people);
					

Table displaying array of arrays

// an array of objects
function Person(firstName, lastName) {
  this.firstName = firstName;
  this.lastName = lastName;
}
var john = new Person("John", "Smith");
var jane = new Person("Jane", "Doe");
var emily = new Person("Emily", "Jones");
console.table([john, jane, emily]);
					

Note that if the array contains objects, then the columns are labeled with the property name.

Table displaying array of objects

// an object whose properties are objects
var family = {};
family.mother = new Person("Jane", "Smith");
family.father = new Person("John", "Smith");
family.daughter = new Person("Emily", "Smith");
console.table(family);
					

Table displaying object of objects

Restricting the columns displayed

默认情况下, console.table() lists all elements in each row. You can use the optional columns parameter to select a subset of columns to display:

// an array of objects, logging only firstName
function Person(firstName, lastName) {
  this.firstName = firstName;
  this.lastName = lastName;
}
var john = new Person("John", "Smith");
var jane = new Person("Jane", "Doe");
var emily = new Person("Emily", "Jones");
console.table([john, jane, emily], ["firstName"]);
					

Table displaying array of objects with filtered output

Sorting columns

You can sort the table by a particular column by clicking on that column's label.

句法

console.table(data [, columns]);
					

参数

data

The data to display. This must be either an array or an object.

columns

An array containing the names of columns to include in the output.

规范

规范 状态 注释
控制台 API
The definition of 'console.table()' in that specification.
实时标准 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
table Chrome 27 Edge 13 Firefox 34 IE 不支持 No Opera 11 Safari 6.1 WebView Android ≤37 Chrome Android 27 Firefox Android 34 Opera Android 11 Safari iOS 7 Samsung Internet Android 1.5

图例

完整支持

完整支持

不支持

不支持

元数据

  • 最后修改: