Skip to content

Instantly share code, notes, and snippets.

@DarrenSem
Last active April 12, 2025 20:18
Show Gist options
  • Save DarrenSem/a0109f95056c0c2512fe2abeb930bab2 to your computer and use it in GitHub Desktop.
Save DarrenSem/a0109f95056c0c2512fe2abeb930bab2 to your computer and use it in GitHub Desktop.
console.tableEach(...args) = args.forEach( arg => console.table(arg) ) - and also console.dirEach().js
// console.tableEach() - and also console.dirEach().js
/////////////////////
console.tableEach = (...args) => args.forEach( arg => console.table(arg) );
// comparing native log() and table() functions vs. new custom function tableEach()...
// log() native function = shows each of the two arrays, first of length (14) then of length (6)
console.log([...Object.keys(location)], [...Object.getOwnPropertyNames(Date)]);
/*
▶(14) ['ancestorOrigins', 'href', 'origin', 'protocol', 'host', 'hostname', 'port', 'pathname', 'search', 'hash', 'assign', 'reload', 'replace', 'toString']
▶(6) ['length', 'name', 'prototype', 'now', 'parse', 'UTC']
*/
// table() native function = shows just a single table for ONLY the FIRST array of length (14)
console.table([...Object.keys(location)], [...Object.getOwnPropertyNames(Date)]);
/*
(index) Value
0 'ancestorOrigins'
1 'href'
2 'origin'
3 'protocol'
4 'host'
5 'hostname'
6 'port'
7 'pathname'
8 'search'
9 'hash'
10 'assign'
11 'reload'
12 'replace'
13 'toString'
▶Array(14)
*/
// new custom function tableEach() = shows a table for EACH of the TWO arrays, first of length (14) then of length (6)
console.tableEach([...Object.keys(location)], [...Object.getOwnPropertyNames(Date)]);
/*
(index) Value
0 'ancestorOrigins'
1 'href'
2 'origin'
3 'protocol'
4 'host'
5 'hostname'
6 'port'
7 'pathname'
8 'search'
9 'hash'
10 'assign'
11 'reload'
12 'replace'
13 'toString'
▶Array(14)
(index) Value
0 'length'
1 'name'
2 'prototype'
3 'now'
4 'parse'
5 'UTC'
▶Array(6)
*/
/////////////////////
console.dirEach = (...args) => args.forEach( arg => console.dir(arg) );
// comparing native log() and dir() functions vs. new custom function dirEach()...
// log() native function = shows each of the two arrays, first of length (14) then of length (6)
console.log([...Object.keys(location)], [...Object.getOwnPropertyNames(Date)]);
/*
▶(14) ['ancestorOrigins', 'href', 'origin', 'protocol', 'host', 'hostname', 'port', 'pathname', 'search', 'hash', 'assign', 'reload', 'replace', 'toString']
▶(6) ['length', 'name', 'prototype', 'now', 'parse', 'UTC']
*/
// dir() native function = shows just a single expandable twistie for just the FIRST array of length (14)
console.dir([...Object.keys(location)], [...Object.getOwnPropertyNames(Date)]);
/* collapsed: (default)
▶Array(14)
*/
/* expanded:
▼Array(14)
0: "ancestorOrigins"
1: "href"
2: "origin"
3: "protocol"
4: "host"
5: "hostname"
6: "port"
7: "pathname"
8: "search"
9: "hash"
10: "assign"
11: "reload"
12: "replace"
13: "toString"
length: 14
▶[[Prototype]]: Array(0)
*/
// dirEach() new custom function = calls dir() for EACH of the TWO arrays, first of length (14) then of length (6)
console.dirEach([...Object.keys(location)], [...Object.getOwnPropertyNames(Date)]);
/* collapsed: (default)
▶Array(14)
▶Array(6)
*/
/* expanded:
▼Array(14)
0: "ancestorOrigins"
1: "href"
2: "origin"
3: "protocol"
4: "host"
5: "hostname"
6: "port"
7: "pathname"
8: "search"
9: "hash"
10: "assign"
11: "reload"
12: "replace"
13: "toString"
length: 14
▶[[Prototype]]: Array(0)
▼Array(6)
0: "length"
1: "name"
2: "prototype"
3: "now"
4: "parse"
5: "UTC"
length: 6
▶[[Prototype]]: Array(0)
*/
/////////////////////
@DarrenSem
Copy link
Author

DarrenSem commented Apr 12, 2025

// see also: consoleRestore.js -- Bookmarklet to bring back [something close to] the native console.log() etc. that have been replaced with a custom override (e.g. by Microsoft Teams April 2025)
// ^ https://gist.github.com/DarrenSem/48f853b2bca6d8334320affde48e225e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment