Skip to content

Instantly share code, notes, and snippets.

@JanneSalokoski
Last active November 28, 2016 07:11
Show Gist options
  • Save JanneSalokoski/654de3e14fb058c2ca8ddaf3af5b27ab to your computer and use it in GitHub Desktop.
Save JanneSalokoski/654de3e14fb058c2ca8ddaf3af5b27ab to your computer and use it in GitHub Desktop.
// Original implementation using Object.values
var cols = Object.values(this.data);
for (var i = 0; i < cols.length; i++)
{
console.log(Object.values(this.data[i]));
new this.Row(Object.values(this.data[i]));
}
// Newer implementation using Object.entries
for (var i = 0; i < Object.entries(this.data).length; i++)
{
var row = [];
for (var j = 0; j < Object.keys(this.data[0]).length; j++)
{
row.push(Object.entries(this.data)[i][1][Object.keys(this.data[0])[j]]);
}
new this.Row(row);
}
// Newest implementation using for...in loops
for (var i in this.data)
{
var row = [];
for (var j in this.data[i])
{
row.push(this.data[i][j]);
}
new this.Row(row);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment