var meal_qty = {};
var label_options = new Array();
var qty_options = new Array();
<?php foreach($label_name as $meal_option_id => $names_of_labels)
{?>
var meal_label_qty = <?php echo $meal_option_id; ?>;
meal_qty[meal_label_qty] = [];
var item = {
mon: <?php echo $_SESSION['protiens']['mon'][$meal_option_id]['qty']?> || null,
tues: <?php echo $_SESSION['protiens']['tues'][$meal_option_id]['qty']?> || null,
wed: <?php echo $_SESSION['protiens']['wed'][$meal_option_id]['qty']?> || null,
thur: <?php echo $_SESSION['protiens']['thur'][$meal_option_id]['qty']?> || null,
fri: <?php echo $_SESSION['protiens']['fri'][$meal_option_id]['qty']?> || null
}
meal_qty[meal_label_qty] = item;
<?php }?>
$('.option').on('click', function() {
$(".tab_options").hide();
var label = $(this).attr('label_option');
console.log(meal_qty[label]);
//$("#qty1").val(meal_qty[label][mon]);
As you can see the last commented out line, it says "mon" is undefined, however how can I get it to show the number? the console before it shows normally as
Object{mon:2, tues:null , wed:1 , thur: null, fri: null}
How can I show just monday which is "2"
[mon], but.monas it is a literal property name, not one stored in a variable namedmon.["mon"]too ; objects' properties can accessed through indexing in JSval(meal_qty[label].mon || 0).