I am reading my html table using javascript and store the value in javascript array everything works fine, I realize that it is automatically adding one extra row i.e { } alternatively
here it my javascript:
var paylist = new Array();
$("#EnterpriseItems tr").each(function () {
var row = $(this);
var pay = {};
pay.ConsolidationSetID = row.find("td").eq(0).html();
pay.ConsolidationSetDescription = row.find("td").eq(1).html();
pay.ElementCode = row.find("td").eq(2).html();
pay.Amount = row.find("td").eq(3).html();
pay.ElementClassification = row.find("td").eq(4).html();
paylist.push(pay);
});
$('#PayElements').val(JSON.stringify(paylist)); //store array in to hidden value pay elements
var hv = $('#PayElements').val(); console.log(hv);
Here is my Json with blank row added alternatively
Accroding to your description and codes,if your blank row is the first or last row,you could use
.not(':first') and .not(':last').
If you have other problems,you could post more details of your requirment and full codes of table to us.It will help us to solve your problem.
More details,you could refer to below codes:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(function () {
var paylist = new Array();
$("#EnterpriseItems tr").not(':first').not(':last').each(function () {
var row = $(this);
var pay = {};
pay.ConsolidationSetID = row.find("td").eq(0).html();
pay.ConsolidationSetDescription = row.find("td").eq(1).html();
pay.ElementCode = row.find("td").eq(2).html();
pay.Amount = row.find("td").eq(3).html();
pay.ElementClassification = row.find("td").eq(4).html();
paylist.push(pay);
});
$('#PayElements').val(JSON.stringify(paylist)); //store array in to hidden value pay elements
var hv = $('#PayElements').val();
console.log(hv);
})
</script>
<table id="EnterpriseItems" runat="server">
<tr></tr>
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
<td>S</td>
<td>D</td>
</tr>
<tr></tr>
</table>
<asp:TextBox ID="PayElements" runat="server"></asp:TextBox>
Result:
Best regards,
Yijing Sun
ASP.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today. Learn more >
Member
40 Points
97 Posts
How to remove alternative blank row from JSON array..?
Jun 28, 2020 07:12 AM|jalali|LINK
I am reading my html table using javascript and store the value in javascript array everything works fine, I realize that it is automatically adding one extra row i.e { } alternatively
here it my javascript:
Here is my Json with blank row added alternatively
Is there anyway I can eliminate the alternate blank rows { } added by javascript.??
Regards;
Imran Jalali.
Contributor
4060 Points
1587 Posts
Re: How to remove alternative blank row from JSON array..?
Jun 29, 2020 05:21 AM|yij sun|LINK
Hi jalali,
Accroding to your description and codes,if your blank row is the first or last row,you could use .not(':first') and .not(':last').
If you have other problems,you could post more details of your requirment and full codes of table to us.It will help us to solve your problem.
More details,you could refer to below codes:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> $(function () { var paylist = new Array(); $("#EnterpriseItems tr").not(':first').not(':last').each(function () { var row = $(this); var pay = {}; pay.ConsolidationSetID = row.find("td").eq(0).html(); pay.ConsolidationSetDescription = row.find("td").eq(1).html(); pay.ElementCode = row.find("td").eq(2).html(); pay.Amount = row.find("td").eq(3).html(); pay.ElementClassification = row.find("td").eq(4).html(); paylist.push(pay); }); $('#PayElements').val(JSON.stringify(paylist)); //store array in to hidden value pay elements var hv = $('#PayElements').val(); console.log(hv); }) </script> <table id="EnterpriseItems" runat="server"> <tr></tr> <tr> <td>A</td> <td>B</td> <td>C</td> <td>S</td> <td>D</td> </tr> <tr></tr> </table> <asp:TextBox ID="PayElements" runat="server"></asp:TextBox>
Result:
Best regards,
Yijing Sun
All-Star
58484 Points
15810 Posts
Re: How to remove alternative blank row from JSON array..?
Jun 29, 2020 09:36 PM|bruce (sqlwork.com)|LINK
or: