I have the problem to save all product_id's with the related quantitie in a multidimensional array.
I have a laravel foreach loop that gives me every product from a bigger products array.
Every single product has a data-id
attribute and an <input type="number">
element to select the quantitie.
Thats how I get all the data-id's and the quantities :
$('.update').on('click', function() {
var ids = $('.list').map(function () {
return $(this).data("id");
}).get();
var quantities = $('input[type=number]').map(function () {
return $(this).val();
}).get();
});
Output of the ids variable: 55,65 Output of the quantities variable: 1,2
My problem is that I need a multidimensinal array that gives me the right product with the related quantitie.
Something like:
var product_data = [
[0] = "id":55,
"quantitie":1,
[1] = "id":65,
"quantitie":2
];
I wasn't able to get it like I need it. I'm still very new to javascript.
Thanks for any help and sorry for my bad english!
what I tried:
for (var i = 0; i < ids.length; i++) {
var product_data = [
id = ids[i],
quantitie = quantities[i]
];
alert(product_data);
}