从console.table()删除索引 [英] remove index from console.table()

查看:67
本文介绍了从console.table()删除索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在控制台中查看一系列数据.

I am viewing an array of data in the console.

console.table(myArray)始终将索引作为第一列.当索引是键时,当查看对象数据时,这很好,但是当索引是数组索引(在我的情况下,它使人分心/烦人)没有此索引,有没有办法显示表?可选的参数允许一个仅显示所需的列...除索引外.

console.table(myArray) always has the index as the first column. This is fine when viewing object data, when the index is the key, but not when the index is the array index (in my case it is distracting/ annoying) Is there any way to show the table without this index? The optional columns parameter allows one to show only wanted columns... except for the index.

推荐答案

MDN Web文档

表中的第一列将被标记(索引).如果数据是数组,则其值将是数组索引.如果数据是对象,则其值为属性名称.请注意,(在Firefox中)console.table只能显示1000行(第一行是标记的索引).

The first column in the table will be labeled (index). If 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).

因此对于数组,您无法隐藏要显示的索引键.但是,作为一种解决方法,您可以将数组转换为使用您的键的对象.

So for an array, you cannot hide the index key to be shown. BUT, as a workaround, you could transform the array into an object where you use your keys.

示例:(打开控制台以查看结果)

Example: (Open your console to see results)

const array = [{myId: 42, name: 'John', color: 'red'}, {myId: 1337, name: 'Jane', color: 'blue'}]

const transformed = array.reduce((acc, {myId, ...x}) => { acc[myId] = x; return acc}, {})

console.table(transformed)

这篇关于从console.table()删除索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆