Loop through an two arrays simultaneously and pass a first element of each array to the function at a time using angular js [new to angular]

后端 未结 3 1439
灰色年华
灰色年华 2021-01-16 12:08
vm.array1.push(content1);
vm.array2.push(content2);

I have a above two arrays with a data of objects pushed at each time and the data modal of each

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-16 13:13

    I'm guessing array1 and array2 are of same length. This should work.

    var vm = {
      save: function(a, b) {
        console.log(a, b)
      }
    };
    vm.array1 = [{
      id: 1
    }, {
      id: 2
    }, {
      id: 3
    }];
    vm.array2 = [{
      id: 4
    }, {
      id: 5
    }, {
      id: 6
    }];
    
    vm.array1.forEach(function(a1, i) {
      vm.save(a1, vm.array2[i]);
    });

提交回复
热议问题