Blog for web developers

Nested Loop javascript

Simple nested loop javascript code

var person = [{
    name : [
	   {firstName: "Ravi", lastName: "Kumar"}
    id       :  5566
	name: [
		{firstName: "John", lastName: "Braman"}
    id       :  96

var item, text;
text="<table class='stack'>";
text+="<thead><tr><th>First Name</th><th>Last Name</th><th>id</th></tr>";
 for(var i=0; i<person.length; i++) {
	for(var j=0; j<person[i].name.length; j++) {
	    text += "<tr><td>"+person[i].name[j].firstName+"</td><td>"+person[i].name[j].lastName+"</td>"+"<td>"+person[i].id+"</td></tr>";
text+= "</table>";
document.getElementById("demo").innerHTML = text;

Santosh Shah

I am a JavaScript developer having enthusiasm on most frontend skills like JavaScript, HTML, CSS, SASS, node, gulp, angular etc. I love exploring new techniques and like to learn new technologies to keep my self up to date.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.