This is the script:
for(var i=0;i < data.length; i++)
{
new_array.push(data[i].catalog_name,data[i].price);
$("#print_receipt").append(
"<table><thead><tr><th>Item Name</th><th>Unit Price</th></thead><tbody>");
for (var j=0;j < new_array.length; j++){
$.each(new_array[j], function( index, value ) {
$("#print_receipt tbody").append("<tr><td>"+value+"</td></tr>");
});
}
$("#print_receipt").append(value+"</tbody></table>");
}
"+value+" This line actually outputs all the values of both arrays that were pushed into new_array by this line new_array.push(data[i].catalog_name,data[i].price);
That is okay, but I want to be able to call them individually. For instance, in the event I want make a table within this $.each loop, how do I know, which columns takes which array's value?
So, how do I call, value.catalog_name or value.price within $.each instead of just value?
new_array.push(data[i].catalog_name,data[i].price);<- price is the only item you have access to in new_array. To access other things, you would need to first create an array, and then push that array into new_array. Then theindex, valuewould have more meaning, as the index would actually be useful.new_array.push({ 'catalog_name': data[i].catalog_name, 'price': data[i].price});...in this case, you're pushing an object into the array rather than pushing two separate values into the array.