The length of an array does not update

1

By giving console to a array , with one (1) object, and in lenght of it, the expected return is obtained, then I update the array value, adding a new position, I give console in array and return says that there are two objects in array and then giving console in lenght of it is returned to me as if there was only one object.

Because the console does not return the correct array size when console is given in length , but returns the right amount when return is array itself?

>

Context

This algorithm was to calculate the best distance between several points. The function itself (least_distance) should receive the routes, which is an object with routes that have not yet been defined, and the exclude, is an object with routes that should be removed from the new route because they have already been used. >

Update05/18/2018Iupdatedthecodewiththeintentionofsimplifyingitandfindingthisproblem,whichuntilthen,iswithoutsolution.

Project: link

    
asked by anonymous 16.05.2018 / 18:28

1 answer

0

If you want to add items to exclude, change the target variable to exclude.push(rotas.destinos[i]);

for (let i in rotas.destinos) {
    for (let j in exclude) {
        if (exclude[j].destino != rotas.destinos[i].destino) {
            exclude.push(rotas.destinos[i]);
        }
    }
}

You have some helpful references here: link

    
18.05.2018 / 19:44