Jazzy 1012
asked on
How to change normal array form to associative in javascript
I have this code:
This is my output:
And it keeps adding, I want my outcome to be:
$(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);
});
});
This is my output:
And 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',
}
}
How can I do this, meaning put the meal_label_qty as the associative of an array
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.