How To Store HTML Markup Inside a Table Into an Array Using jQuery

How To Store HTML Markup Inside a Table Into an Array Using jQuery

Can you please take a look at  This Demo and let me know how I can store html markup from a table td into an array as an item of array?

I need to store the selected value of a row in an array and store in in database and eventually present it on the front end with button again.

var arr = []; var d = new Date(); var month = d.getMonth()+1; var day = d.getDate(); var today = d.getFullYear() + '/' + ((''+month).length<2 ? '0' : '') + month + '/' + ((''+day).length<2 ? '0' : '') + day; var user = "foo"; $(".adder").on("click", function(){ var $this = $(this); var getarray = []; $this.closest('tr').find('td:not(td:first, td:last)').each(function(){ getarray.push($(this).text()); }); getarray.push(user); getarray.push(today); alert(getarray); });
body{padding:30px;} .adder{cursor:pointer;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table class="table table-striped"> <tr> <td>1</td> <td><button class="adder">Add data</button></td> <td>Smith</td> <td>50</td> <td><span class="glyphicon glyphicon-plus adder" aria-hidden="true"></span></td> </tr> <tr> <td>2</td> <td><button class="adder">Add data</button></td> <td>Jackson</td> <td>94</td> <td><span class="glyphicon glyphicon-plus adder" aria-hidden="true"></span></td> </tr> </table>