1

I have the following for loop in which this_block gets created and then filled in:

for (i = learning_trial_idx.length - 1; i >= 0; i--) {

  target = Math.floor(Math.random())

  these_trials = learning_trial_idx.filter(x => x.from != target)

  this_block = [];

  for (let i = 0; i < these_trials.length; i++) {
      this_block.push(these_trials[i])
  }

  this_block = this_block.filter(function (a) {
    var key = a.to + '|' + a.from;
    if (!this[key]) {
        this[key] = true;
        return true;
      }
    }, Object.create(null));
}

How can I go about storing this_block each time into something like const all_blocks = {}, which is defined outside of the for loop?

1 Answer 1

1

You can do that by declaring first const allBlocks = { thisBlock: [] } and push-ing inside thisBlock inside the for loop: allBlocks.thisBlock.push(theseTrials[i])

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.