Nested array handling


#1

I have so arrays which I either wish to flatten or loop through and display based on a condition

this method fires first

 //Fetch Transaction information
    fecthLedgerTransactions() {
      server
        .transactions()
        .forLedger(this.id)
        .call()
        .then(accountResults => {
          this.ledgerTranscations = accountResults.records;
          this.ledgerTranscations.forEach(ledgerTranscation => {
            this.fecthTransactionOperations(ledgerTranscation.id);
          });
        })
        .catch(function(err) {
          console.log(err);
        });
    }, 

which triggers anotehr call to get extra data from another end point:
//Fetch Operations in each Transaction
fecthTransactionOperations(val) {
server
.operations()
.forTransaction(val)
.call()
.then(operationsResult => {
this.catchTransactionOperations.push(operationsResult.records);
})
.catch(function(err) {
console.log(err);
});
}

That’s then sending it to a data object, I then I want to flatten that array and loop through it and display results based on a matchup/condition

I have tried push, un-shift, and flat. Right now I have a watch pushing to an object but I can’t seem to get it to flatten and not be nested

  watch: {
    catchTransactionOperations() {
        this.transactionOperations.push(this.catchTransactionOperations);
    }
  },

Any ideas whould be awesome!


#2

You mean concatenate the new array elements, rather than pushing the array into a single element?

You can use “concat” or use the spread opeartor:

watch: {
    catchTransactionOperations() {
        this.transactionOperations.push(...this.catchTransactionOperations);
    }
  },