php - Laravel - Javascript - save all quantities and id's in a multidimensional array -


i have problem save product_id's related quantitie in multidimensional array.

i have laravel foreach loop gives me every product bigger products array.

every single product has data-id attribute , <input type="number"> element select quantitie.

thats how data-id's , 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 ids variable: 55,65 output of quantities variable: 1,2

my problem need multidimensinal array gives me right product related quantitie.

something like:

var product_data = [     [0] = "id":55,           "quantitie":1,     [1] = "id":65,           "quantitie":2 ]; 

i wasn't able need it. i'm still new javascript.

thanks , sorry bad english!


what tried:

    (var = 0; < ids.length; i++) {         var product_data = [             id = ids[i],             quantitie = quantities[i]         ];         alert(product_data);     } 

you can try combining 2 arrays together. there 2 assumptions in that

  1. both arrays same length
  2. both arrays correctly sorted

var ids = ["1", "2"];  var quantities = [ "30", "40" ];    var res = [];  ids.foreach(function(id, i) {     res.push({ id: id, quantitie: quantities[i] });  });  console.log(res);


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -