/**
* Grid Builder
* Create a function "gridify" that accepts an array of similar objects
* It will output a "table" in the console
* The header row will be the property names and should display ONCE
* The body rows will be the property values
*
* Hint: use tabs to align, "\t" is the tab character
*
*/
/* your code here */
gridify([{
name: "Ryan",
value: 913
}, {
name: "Jimmy",
value: 20003
}, {
name: "Donna",
value: 923
}]);
function gridify(arr) {
var fobj = arr[0];
var header = "";
for (var key in fobj) {
header += key.substr(0,1).toUpperCase()+key.substr(1);
header += "\t";
}
console.log(header);
var len = arr.length;
for (var i=0; i<len; i++) {
var elem = "";
fobj = arr[i];
for ( key in fobj) {
elem += fobj[key];
elem += "\t";
}
console.log(elem);
}
}
/*
ex output:
Name Value
Ryan 913
Jimmy 20003
Donna 923
*/
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.