Smaller number array length than correct - JS

Asked

Viewed 22 times

2

I am using an array, where when giving a console.log The same shows 2 items inside, just below in another console.log with length it marks 1, but it is certain to have 2 items in the array.

inserir a descrição da imagem aqui

Code:

console.log(av)
console.log(av.length)

Previously, using the function slice(), she repeated all arrays when giving a push(). Then I had to get one to use the for().

In the above example the variable is global.

  • In the image itself indicates length:2. If it appears to him 1 it is because anything in the middle has tampered with the array

  • Put the code here for us please

  • @Isac The console.log is one below the other (line: 462 and 463)... I suspect that one of the problems is not to appear [array(124)][Array(123)] in the title.

  • @Brunomorales The code is very big, tomorrow I will unlock it and try to post part of it...

  • 1

    Hi @abcd! I think this question is answered by another that I have marked now. Basically what the browser shows on the console is changed after the moment the console.log run, because it is an array/pointer to the original. If you do console.log(JSON.stringify(av)); the result will already be as expected.

  • 1

    @Sergio Thanks, that was right, console.logthere was a push. And that’s what he was doing. ATT

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.