0

I would like to sort my array to do this I declared 2 temporary array but the both array are already filled even just after the initialization. Seems like i got a memory problem


let tmpCheckDeals : any[] = [];
let tmpUncheckDeals: any[] = [];

    console.log('Init :' , tmpCheckDeals, tmpUncheckDeals);
    this.checkedDeals.forEach(element => {
      tmpCheckDeals.push(element);
    });
    for (let i = 0; i < this.deals.list.length; i++) {
      let isInside : boolean = false;
      const element = this.deals.list[i];

      for (let a = 0; a < this.checkedDeals.length; a++) {
        const element1 = this.checkedDeals[a];
        if(element == element1)
          isInside = true;
      }

      if(isInside == false) {
        console.log('Passe');
        tmpUncheckDeals.push(element);
      }
      isInside = false;
    }

Result of my console: console

As you can see my arrays are already filled

Do you have an idea why i get this error pls ? Thanks

  • Use `console.log('Init :' , JSON.stringify(tmpCheckDeals), JSON.stringify(tmpUncheckDeals));` instead. If you hover over that i in a blue square, it mentions that this data is not as of the time it was logged. – Heretic Monkey Jun 13 '19 at 15:31
  • Possible duplicate of [weird array behaviour in javascript](https://stackoverflow.com/questions/49838597/weird-array-behaviour-in-javascript) – Heretic Monkey Jun 13 '19 at 15:32

1 Answers1

0

Your code is working as expected. The console displays the value of the array after the entire code has been executed. If you hover over the "i" icon near the array, it would say "Value below was evaluated just now".

For confirmation, you can check by commenting out the remaining code, except the console log.