Itrate objects in jquery

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$(document).ready(function()
{
var rows = '<table border="1"><tr><th> Key</th><th> Value</th></tr>';
var obj = {
"name": "saurabh",
"age": "25",
"project": "coding 4 developers"
};
$.each( obj, function( key, value ) {
rows = rows + '<tr><td> '+key+'</td><td> '+value+'</td></tr>';
});
rows = rows + '</table>';
$('#table').html(rows);
});
</script>

<div id="table"></div>

Share This:

Leave a Reply

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