Skip to content

Instantly share code, notes, and snippets.

@mpmckenna8
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpmckenna8/9166197 to your computer and use it in GitHub Desktop.
Save mpmckenna8/9166197 to your computer and use it in GitHub Desktop.
Using console.table() to check out objects

So I've been objectifying data lately and when I'm trying to make it do stuff in a browser, especially with d3.js like in the example, all the nested tabs make those objects hart to read.

But with console.table() you get a nice view of your objects in a table in the Javascript Console!

Don't know if it's supported everywhere but works well for me in Chrome. If you open your JavaScript Console and reload the page hopefully you'll see a nice table and not lots of errors like I usually see.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Using console.table()</title>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script type="text/javascript" src="./UNhcrPOC50.js"></script>
</head>
<body>
Open up that JavaScript Console and refresh the page to hopefully see a working example of console.table() from the below code in action.
<svg class="chart"></svg>
<script type="text/javascript">
var width = 500,
barheight= 20;
var x = d3.scale.linear()
.range([0,width]);
//var chart = d3.select(".chart").att("width",width);
// console.table(d3.values(top50POCunhcr))
var tops = d3.values(top50POCunhcr);
console.table(tops);
</script>
</body>
</html>
top50POCunhcr = [
{
"_id" : "Colombia",
"totrefs" : 4356236
},
{
"_id" : "Afghanistan",
"totrefs" : 4023752
},
{
"_id" : "Democratic Republic of the Congo",
"totrefs" : 3568381
},
{
"_id" : "Stateless",
"totrefs" : 3358415
},
{
"_id" : "Syrian Arab Republic",
"totrefs" : 2835026
},
{
"_id" : "Sudan",
"totrefs" : 2557771
},
{
"_id" : "Somalia",
"totrefs" : 2313460
},
{
"_id" : "Iraq",
"totrefs" : 2120666
},
{
"_id" : "Pakistan",
"totrefs" : 970943
},
{
"_id" : "Myanmar",
"totrefs" : 871354
},
{
"_id" : "Azerbaijan",
"totrefs" : 617969
},
{
"_id" : "Yemen",
"totrefs" : 497000
},
{
"_id" : "South Sudan",
"totrefs" : 451345
},
{
"_id" : "Kenya",
"totrefs" : 422424
},
{
"_id" : "Philippines",
"totrefs" : 418689
},
{
"_id" : "Serbia (and Kosovo: S/RES/1244 (1999))",
"totrefs" : 405261
},
{
"_id" : "Mali",
"totrefs" : 379834
},
{
"_id" : "Various",
"totrefs" : 361377
},
{
"_id" : "Viet Nam",
"totrefs" : 338344
},
{
"_id" : "Burundi",
"totrefs" : 328052
},
{
"_id" : "Eritrea",
"totrefs" : 305850
},
{
"_id" : "Georgia",
"totrefs" : 293530
},
{
"_id" : "Sri Lanka",
"totrefs" : 284776
},
{
"_id" : "Côte d'Ivoire",
"totrefs" : 270725
},
{
"_id" : "Central African Republic",
"totrefs" : 254307
},
{
"_id" : "Libya",
"totrefs" : 244545
},
{
"_id" : "Bosnia and Herzegovina",
"totrefs" : 222349
},
{
"_id" : "Turkey",
"totrefs" : 212925
},
{
"_id" : "China",
"totrefs" : 208730
},
{
"_id" : "Chad",
"totrefs" : 188010
},
{
"_id" : "Kyrgyzstan",
"totrefs" : 176549
},
{
"_id" : "Russian Federation",
"totrefs" : 136193
},
{
"_id" : "Zimbabwe",
"totrefs" : 121710
},
{
"_id" : "Iran (Islamic Republic of)",
"totrefs" : 121566
},
{
"_id" : "Ethiopia",
"totrefs" : 121462
},
{
"_id" : "Angola",
"totrefs" : 116751
},
{
"_id" : "Western Sahara",
"totrefs" : 116559
},
{
"_id" : "Rwanda",
"totrefs" : 107694
},
{
"_id" : "Liberia",
"totrefs" : 97307
},
{
"_id" : "Palestinian",
"totrefs" : 97258
},
{
"_id" : "Croatia",
"totrefs" : 84570
},
{
"_id" : "Congo",
"totrefs" : 61434
},
{
"_id" : "Haiti",
"totrefs" : 46745
},
{
"_id" : "Bhutan",
"totrefs" : 41673
},
{
"_id" : "United Republic of Tanzania",
"totrefs" : 37128
},
{
"_id" : "Mauritania",
"totrefs" : 36757
},
{
"_id" : "Uganda",
"totrefs" : 34439
},
{
"_id" : "Ghana",
"totrefs" : 32578
},
{
"_id" : "Nigeria",
"totrefs" : 32181
},
{
"_id" : "Guinea",
"totrefs" : 29040
}
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment