E
E
Egor Antropov2019-06-05 16:01:03
JavaScript
Egor Antropov, 2019-06-05 16:01:03

Why does some see an object that doesn't exist?

There is a button that checks the array for the presence of an object, if there is no object, this object is added.
At the first check (when the array is empty), the required object is added to the array
. But for some reason, further, when checking, it turns out that there is an object in the array that is not there.
5cf7bd0026a23906049783.png5cf7bd08ca21d524120634.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Baranchugov, 2019-06-09
@AlexanderBaranchugov

What logic do you think should be put into the variable i?
Judging by the code, the variable iwill take on a value trueif at least one element elemin the array cartwill not be equal scope.items
Accordingly, ALMOST ANY newly added element scope.itemsto the array cartwill not be equal to AT LEAST ONE that is already in the array => you will get the output i = true
when i == = true code block on lines 58 - 61 will not be executed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question