Why Console.log Displays Incorrect Object's Values?
I don't understand why console.log displays that d1 contains [100,200,300] before I even introduced these numbers. Regular for loop displays internals of d1 correctly though. Can s
Solution 1:
that's because what is in the console is the reference of dt
not a copy.
you can copy the object and log it (the code from this question ).
or you can log the string that represents it using JSON.stringify
.
console.log( JSON.stringify(dt) );
will print it as string.
Also if you are using lodash
then you can use console.log(_.cloneDeep(dt))
to clone and log the correct values inside the object at that very moment.
Post a Comment for "Why Console.log Displays Incorrect Object's Values?"