1

This might seem similar to some questions, but I don't have the same problems as those posters, so I don't think this is a duplicate.

if(inputSize instanceof NeuralNet){
            console.log('NN being copied');
            console.log(inputSize);
            console.log('Copying neural net...');
            this.layerA = [];
            for(let i = 0; i < inputSize.layerA.length; i++)
                this.layerA[i] = inputSize.layerA[i].slice();
            this.layerB = [];
            for(let i = 0; i < inputSize.layerB.length; i++)
                this.layerB[i] = inputSize.layerB[i].slice();
            console.log(this.layerA);
            console.log(this.layerB);
            console.log(this);
            console.log('Finished copying NN');
            this.biasA = inputSize.biasA;
            this.biasB = inputSize.biasB;
            console.log(this.layerA);
            this.fitness = 0;
            console.log(this);
}

This is the part of my code that has issues. I have valid values in the arrays of this.layerA and this.layerB when I apply console.log on them, so I know that there isn't an issue of me logging the arrays before they are populated with values.

Part of log:

However, when I log "this", I get weird values for layerA and layerB. The arrays still have the right dimensions, but most of the values within them are undefined, with a few numerical values (sometimes, not in this case).

Moreover, when I log this.layerA and this.layerB right after logging this, they still have the correct values. I have absolutely no idea why this is the case. I appreciate any help I can get. Thank you!

  • 1
    I think `layerB` (and maybe `layerA` as well) might have gotten reassigned. See https://stackoverflow.com/questions/23429203/weird-behavior-with-objects-console-log For better answers, provide a [MCVE], not a picture of code output – CertainPerformance Jul 29 '18 at 03:54
  • Thanks for the help! Sorry for not providing a complete executable example. I'll make sure to check for that next time. I still don't get a proper value when logging "this", but I guess it's nice enough to know the values within the arrays are still valid. – user2107351 Jul 29 '18 at 04:03

0 Answers0