Just another WordPress site

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;

The post Nested Loop javascript appeared first on Santosh Shah.


Leave a Reply

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