1
In giving console
in a array
, with an object(1), and lenght
from it is obtained the expected return, then update the value of the array, adding a new position, give console in the array
and the return says that there are two objects in the array
and then to give console
in the lenght
of him is returned to me as if there were only one object.
Because the console does not return the correct array size when given console
right in the length
, but returns the right amount when the return is itself array
?
Context
This algorithm was to calculate the best distance between several points. The function itself (minus distance) should receive the routes, which is an object with the routes that have not yet been defined, and exclude is an object with the routes that should be removed from the new route because they have already been used.
Update 18/05/2018 I updated the code in order to simplify it and find this problem, which until then, is unsolved.
What result would you like to receive in these
console.log
s?– Wees Smith
In the last line "exclude.lenght" should return 2, conformeo previous console, which returned two positions.
– Gustave Dupre
I’m sorry, I don’t understand, you can explain to me better?
– Gustave Dupre
Guy I made a tests here with its function, and the consoles logs return correctly. If I pass an object inside the array in the parameter
exclude
, shows only 1, if I step 2, shows 2, and so on. I could not replicate the problem in question if I understood correctly.– guastallaigor
@guastallaigor did you take a look at jsfiddle? La my problem is being replicated on the console. It doesn’t make any sense to me, but I always replicate it. At first I was doing it in Angular, I switched to Youtube and now I’m doing it directly in javascript and always at this point I have this same problem.
– Gustave Dupre
Your fiddle doesn’t give any output on the console to me. It seems like it doesn’t even enter the function
menor_distancia
– bfavaretto
@bfavaretto this print I took is from the fiddle island. teistei now again and agree, can take another look for kindness?
– Gustave Dupre
Tell me an updated fiddle URL, that above remains the same thing.
– bfavaretto
@bfavaretto, I think this link is right. Take a look at this video: https://youtu.be/NbrhkFZK9GU https://jsfiddle.net/anndreyy/wbzbgj0z/2/
– Gustave Dupre
Look, I think it’s simply a matter of asymptomatism. When you log the entire object, the console only pulls the data of this object, including length, at the time you click on the arrow to open. Then the moment you log into length 1 is earlier than the moment you expand the object on the console and find length 2. Hover your mouse over that
[i]
that appears next to the expand object arrow on the console. It says exactly that, that the object is calculated at the time of that click.– bfavaretto
At first moment I imagined it was something like this, after I put a delay, using setTimeout, the return is as expected. However, I wanted to understand why this happens, at what point it happens.
– Gustave Dupre
I did a test here and it worked correctly
– Marcelo Vieira
On the last console displayed 2? Because here continues 1.
– Gustave Dupre