Link to home
Start Free TrialLog in
Avatar of Jazzy 1012
Jazzy 1012

asked on

How to change normal array form to associative in javascript

I have this code:
$(document).ready(function() {
	var meal_qty = new Array(); 
	var label_options = new Array(); 
	var qty_options = new Array();

	$(".protein-option").click(function() {
	
		var meal_label_qty = $(this).attr("label_option");
		var id_mon_qty = $("#qty1").val();
		var id_tues_qty = $("#qty2").val();
		var id_wed_qty = $("#qty3").val();
		var id_thur_qty = $("#qty4").val();
		var id_fri_qty = $("#qty5").val();

		meal_qty.push(meal_label_qty,id_mon_qty,id_tues_qty,id_wed_qty,id_thur_qty,id_fri_qty);

		alert(meal_qty);
});
});

Open in new window


This is my output:
User generated imageAnd it keeps adding, I want my outcome to be:
var meal_qty
{
[1012] {
               [mon] => 'qty1value',
              [tues] => 'qty2value',
              [wed] => 'qty3value', ...}
(ALL THE WAY TILL FRIDAY)
[10112] {
               [mon] => 'qty1value',
              [tues] => 'qty2value',
              [wed] => 'qty3value',
}

}

Open in new window

How can I do this, meaning put the meal_label_qty as the associative of an array
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial