jquery – How to loop through an array of JSON using for loop in javascript and make a table row using it

I do have this sample array of JSON, and I do not know how to loop through them and use it in creating a table row.

Sample code:

var data = [

I did use this method:

 $.each(data, function (key, value) {
        rows += "<tr id=" + key + "><td>" + value.foo1+ "</td><td>" + value.foo2+ "</td><td>" + value.foo3+    "</td><td>"</tr>";

//But I want to make it more flexible, so that I can reuse it in making another rows from another array of JSON, like this scenario:

var dataNew = [

//Now I cannot use the method above

Read more here: Source link