I am trying to push Id into an array of Json objects. Each object must have a "JobId": the value is "inserted" before sending it to apiController. I am trying to use the forEach loop for this, but I am stuck. Right now, instead of inserting this into every object in the array, it is inserting at the end of the array. I have a plunkr installation. plunkr
$scope.array = [{ ESOURCELINEID:"5464", QBRFQLINESUPPLIERPARTNUMBER:"HW12", QBRFQLINESUPPLIERQUOTEUOM:"ft" }, { ESOURCELINEID:"8569", QBRFQLINESUPPLIERPARTNUMBER:"LT34", QBRFQLINESUPPLIERQUOTEUOM:"Meter" }]; var JobId = 143; $scope.array.forEach(function (newJobItem) { $scope.array.push({'JobId' : JobId}); }); var index = 0; $scope.array.forEach(function (newJobItem) { console.log('newJobItem #' + (index++) + ': ' + JSON.stringify(newJobItem)); });
source share