Click here to Skip to main content
16,004,761 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How do i use plunker to display the animals table, if i run this js code in plunker for some reason the animal table will not be displayed.

JavaScript
var func1 = function(){
	func2();		
};
var Car = function(){
	this.funcX = function(){
		this.funcY();
	}
	this.funcY = function(){
		this.funcZ();
	}
}
var car = new Car();


console.log(car);

var animals = [
 { animal: 'Horse', name: 'Henry', age: 43 },
 { animal: 'Dog', name: 'Fred', age: 13 },
 { animal: 'Cat', name: 'Frodo', age: 18 }
];
console.table(animals);


What I have tried:

Plunker[^]
Posted
Updated 30-Nov-16 8:58am

1 solution

console.table will print in tablular form on the console of the browser developer tools, for that press F12 in the page and then refresh the page, you and from the dev tool bar navigate to console, you will see the data logged in tabular form then.

you will need to add some html first and then using javascript add the rows with data like:

HTML
<table id="animalstable">
      <thead>
        <tr><td>Animal</td>
        <td>Name</td>
        <td>Age</td>
      </tr></thead>
</table>


and then in js file add code like:

JavaScript
document.addEventListener('DOMContentLoaded', function() {

  var animals = [{
    animal: 'Horse',
    name: 'Henry',
    age: 43
  }, {
    animal: 'Dog',
    name: 'Fred',
    age: 13
  }, {
    animal: 'Cat',
    name: 'Frodo',
    age: 18
  }];
  console.log(animals);
  var table = document.getElementById("animalstable");
  for (var index in animals) {
    console.log(index);
    table.innerHTML += "" + animals[index].animal + "" + animals[index].name + "" + animals[index].age + "";
  }

}, false);


See the updated Plunker demo here
 
Share this answer
 
v2
Comments
forte74 30-Nov-16 22:03pm    
I'm gettting in the console script.js:37 Uncaught ReferenceError: animals is not defined(…)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900