var menu_items = 0;
$(".trueol").each(function(){
menu_items = menu_items + 1;
});
var product_price = new Array(menu_items);
var product_name = new Array(menu_items);
$(".price").each(function(){
var i = 0;
product_price[i] = $(this).data("p");
document.write(product_price[i]); /*Inner document.write*/
i++;
});
document.write(product_price[2]); /*Outer document.write*/
$(".menu_product").each(function(){
var j = 0;
product_name[j] = $(this).text();
document.write(product_name[j]); /*Inner document.write*/
j++;
});
document.write(product_name[2]); /* Outer document.write */
Here, the inner document.write works just fine but outer ones print undefined. P.S menu_items has a value of 4 after iterating. What's the problem ?