In my code, there is a nested array called $scope.instruments which contains the following:
Collapsed view:
https://i.sstatic.net/Aii9N.png
Expanded view:
https://i.sstatic.net/Fh5Bz.png
Additionally, I have an object:
https://i.sstatic.net/qd8Xn.png
This object has two arrays: AttributeID and SPAttributeRefID.
Currently, I am flattening the $scope.instruments array using the reduce function as shown below:
$scope.instruments = $scope.instruments.reduce(function (result, instrument) {
result[instrument.ID] = instrument;
return result
}, {});
Next, I extract the AttributeID from the object and assign it to a variable in this manner:
$scope.recordInstrument = $scope.instruments[data.AttributeID[0]].ID;
Instead of using the reduce function, I would like to achieve the same result using a loop. I tried experimenting with a for loop but haven't been successful so far:
var arrInstruments = $scope.instruments;
var arrLength = arrInstruments.length;
for (var i = 0; i < arrLength; i++) {
console.log(arrInstruments[i]);
}
If anyone can assist me in converting the code that uses reduce to use a loop while retaining the functionality of assigning AttributeID, I would greatly appreciate it.
Thank you very much.