Array has records but showing array length 0 in console










0















There is files array in my code. When i adds new file, its showing incorrect length of array. But, if i checked the length with settimeout its showing correct length.



console.log('row.myDocuments: ', row.myDocuments); 
console.log('length: ', row.myDocuments.length);


Getting results in console like this,



enter image description here



Every time when i add new file, the length getting in console is (actual length -1)










share|improve this question
























  • is adding new file, an asynchronous operation?

    – Sarthak Aggarwal
    Nov 14 '18 at 10:21











  • no... its not asynchronous operation.

    – Mangesh Daundkar
    Nov 14 '18 at 10:22











  • Share all relevant code for this.

    – Sunil Singh
    Nov 14 '18 at 10:23











  • post the relevant code block too...

    – Jai
    Nov 14 '18 at 10:23











  • stackoverflow.com/questions/38660832/…

    – Chellappan
    Nov 14 '18 at 10:28















0















There is files array in my code. When i adds new file, its showing incorrect length of array. But, if i checked the length with settimeout its showing correct length.



console.log('row.myDocuments: ', row.myDocuments); 
console.log('length: ', row.myDocuments.length);


Getting results in console like this,



enter image description here



Every time when i add new file, the length getting in console is (actual length -1)










share|improve this question
























  • is adding new file, an asynchronous operation?

    – Sarthak Aggarwal
    Nov 14 '18 at 10:21











  • no... its not asynchronous operation.

    – Mangesh Daundkar
    Nov 14 '18 at 10:22











  • Share all relevant code for this.

    – Sunil Singh
    Nov 14 '18 at 10:23











  • post the relevant code block too...

    – Jai
    Nov 14 '18 at 10:23











  • stackoverflow.com/questions/38660832/…

    – Chellappan
    Nov 14 '18 at 10:28













0












0








0








There is files array in my code. When i adds new file, its showing incorrect length of array. But, if i checked the length with settimeout its showing correct length.



console.log('row.myDocuments: ', row.myDocuments); 
console.log('length: ', row.myDocuments.length);


Getting results in console like this,



enter image description here



Every time when i add new file, the length getting in console is (actual length -1)










share|improve this question
















There is files array in my code. When i adds new file, its showing incorrect length of array. But, if i checked the length with settimeout its showing correct length.



console.log('row.myDocuments: ', row.myDocuments); 
console.log('length: ', row.myDocuments.length);


Getting results in console like this,



enter image description here



Every time when i add new file, the length getting in console is (actual length -1)







arrays angular console






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 10:21









Flimzy

39.3k106698




39.3k106698










asked Nov 14 '18 at 10:19









Mangesh DaundkarMangesh Daundkar

39828




39828












  • is adding new file, an asynchronous operation?

    – Sarthak Aggarwal
    Nov 14 '18 at 10:21











  • no... its not asynchronous operation.

    – Mangesh Daundkar
    Nov 14 '18 at 10:22











  • Share all relevant code for this.

    – Sunil Singh
    Nov 14 '18 at 10:23











  • post the relevant code block too...

    – Jai
    Nov 14 '18 at 10:23











  • stackoverflow.com/questions/38660832/…

    – Chellappan
    Nov 14 '18 at 10:28

















  • is adding new file, an asynchronous operation?

    – Sarthak Aggarwal
    Nov 14 '18 at 10:21











  • no... its not asynchronous operation.

    – Mangesh Daundkar
    Nov 14 '18 at 10:22











  • Share all relevant code for this.

    – Sunil Singh
    Nov 14 '18 at 10:23











  • post the relevant code block too...

    – Jai
    Nov 14 '18 at 10:23











  • stackoverflow.com/questions/38660832/…

    – Chellappan
    Nov 14 '18 at 10:28
















is adding new file, an asynchronous operation?

– Sarthak Aggarwal
Nov 14 '18 at 10:21





is adding new file, an asynchronous operation?

– Sarthak Aggarwal
Nov 14 '18 at 10:21













no... its not asynchronous operation.

– Mangesh Daundkar
Nov 14 '18 at 10:22





no... its not asynchronous operation.

– Mangesh Daundkar
Nov 14 '18 at 10:22













Share all relevant code for this.

– Sunil Singh
Nov 14 '18 at 10:23





Share all relevant code for this.

– Sunil Singh
Nov 14 '18 at 10:23













post the relevant code block too...

– Jai
Nov 14 '18 at 10:23





post the relevant code block too...

– Jai
Nov 14 '18 at 10:23













stackoverflow.com/questions/38660832/…

– Chellappan
Nov 14 '18 at 10:28





stackoverflow.com/questions/38660832/…

– Chellappan
Nov 14 '18 at 10:28












1 Answer
1






active

oldest

votes


















1














This is related to Chrome dev tools. You see the little "i" in a blue square next to ""? If you hover it with your mouse, it says "value below was evaluated just now". It means that at the time you logged your array (which is actually a javascript Object), it was empty, but later Chrome detected a change, and updated the array in the console.



(And that is only if you expand it using the little arrow, you can see the array was empty at the time it was logged since it looks like this "", otherwise it would have looked like this "[...]").



Chrome updates object when you log them, but not simple values. Array.length is a number, so when you log it, it gives you its value (0), and if Array.length changes later, it will not update the console; but if you log it after the change (as with your timeout), it will log the more recent value.






share|improve this answer

























  • Thanks Alex... But is there any alternative to settimeout. Actually, i'm expecting actual value without settimeout.

    – Mangesh Daundkar
    Nov 14 '18 at 10:44











  • You need the actual value in the console? In the code it will always be the right value, if the array is empty then its length will always be 0. What you could do instead, is log a copy of the array so that the logged array and its length match. So change console.log(myArray) to console.log(myArray.slice()). Another option is to add a breakpoint in the "Sources" section of chrome devtools, where it will show the most recent value next to the variable name.

    – Alex D
    Nov 14 '18 at 11:00











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297827%2farray-has-records-but-showing-array-length-0-in-console%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














This is related to Chrome dev tools. You see the little "i" in a blue square next to ""? If you hover it with your mouse, it says "value below was evaluated just now". It means that at the time you logged your array (which is actually a javascript Object), it was empty, but later Chrome detected a change, and updated the array in the console.



(And that is only if you expand it using the little arrow, you can see the array was empty at the time it was logged since it looks like this "", otherwise it would have looked like this "[...]").



Chrome updates object when you log them, but not simple values. Array.length is a number, so when you log it, it gives you its value (0), and if Array.length changes later, it will not update the console; but if you log it after the change (as with your timeout), it will log the more recent value.






share|improve this answer

























  • Thanks Alex... But is there any alternative to settimeout. Actually, i'm expecting actual value without settimeout.

    – Mangesh Daundkar
    Nov 14 '18 at 10:44











  • You need the actual value in the console? In the code it will always be the right value, if the array is empty then its length will always be 0. What you could do instead, is log a copy of the array so that the logged array and its length match. So change console.log(myArray) to console.log(myArray.slice()). Another option is to add a breakpoint in the "Sources" section of chrome devtools, where it will show the most recent value next to the variable name.

    – Alex D
    Nov 14 '18 at 11:00
















1














This is related to Chrome dev tools. You see the little "i" in a blue square next to ""? If you hover it with your mouse, it says "value below was evaluated just now". It means that at the time you logged your array (which is actually a javascript Object), it was empty, but later Chrome detected a change, and updated the array in the console.



(And that is only if you expand it using the little arrow, you can see the array was empty at the time it was logged since it looks like this "", otherwise it would have looked like this "[...]").



Chrome updates object when you log them, but not simple values. Array.length is a number, so when you log it, it gives you its value (0), and if Array.length changes later, it will not update the console; but if you log it after the change (as with your timeout), it will log the more recent value.






share|improve this answer

























  • Thanks Alex... But is there any alternative to settimeout. Actually, i'm expecting actual value without settimeout.

    – Mangesh Daundkar
    Nov 14 '18 at 10:44











  • You need the actual value in the console? In the code it will always be the right value, if the array is empty then its length will always be 0. What you could do instead, is log a copy of the array so that the logged array and its length match. So change console.log(myArray) to console.log(myArray.slice()). Another option is to add a breakpoint in the "Sources" section of chrome devtools, where it will show the most recent value next to the variable name.

    – Alex D
    Nov 14 '18 at 11:00














1












1








1







This is related to Chrome dev tools. You see the little "i" in a blue square next to ""? If you hover it with your mouse, it says "value below was evaluated just now". It means that at the time you logged your array (which is actually a javascript Object), it was empty, but later Chrome detected a change, and updated the array in the console.



(And that is only if you expand it using the little arrow, you can see the array was empty at the time it was logged since it looks like this "", otherwise it would have looked like this "[...]").



Chrome updates object when you log them, but not simple values. Array.length is a number, so when you log it, it gives you its value (0), and if Array.length changes later, it will not update the console; but if you log it after the change (as with your timeout), it will log the more recent value.






share|improve this answer















This is related to Chrome dev tools. You see the little "i" in a blue square next to ""? If you hover it with your mouse, it says "value below was evaluated just now". It means that at the time you logged your array (which is actually a javascript Object), it was empty, but later Chrome detected a change, and updated the array in the console.



(And that is only if you expand it using the little arrow, you can see the array was empty at the time it was logged since it looks like this "", otherwise it would have looked like this "[...]").



Chrome updates object when you log them, but not simple values. Array.length is a number, so when you log it, it gives you its value (0), and if Array.length changes later, it will not update the console; but if you log it after the change (as with your timeout), it will log the more recent value.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 10:44

























answered Nov 14 '18 at 10:36









Alex DAlex D

464




464












  • Thanks Alex... But is there any alternative to settimeout. Actually, i'm expecting actual value without settimeout.

    – Mangesh Daundkar
    Nov 14 '18 at 10:44











  • You need the actual value in the console? In the code it will always be the right value, if the array is empty then its length will always be 0. What you could do instead, is log a copy of the array so that the logged array and its length match. So change console.log(myArray) to console.log(myArray.slice()). Another option is to add a breakpoint in the "Sources" section of chrome devtools, where it will show the most recent value next to the variable name.

    – Alex D
    Nov 14 '18 at 11:00


















  • Thanks Alex... But is there any alternative to settimeout. Actually, i'm expecting actual value without settimeout.

    – Mangesh Daundkar
    Nov 14 '18 at 10:44











  • You need the actual value in the console? In the code it will always be the right value, if the array is empty then its length will always be 0. What you could do instead, is log a copy of the array so that the logged array and its length match. So change console.log(myArray) to console.log(myArray.slice()). Another option is to add a breakpoint in the "Sources" section of chrome devtools, where it will show the most recent value next to the variable name.

    – Alex D
    Nov 14 '18 at 11:00

















Thanks Alex... But is there any alternative to settimeout. Actually, i'm expecting actual value without settimeout.

– Mangesh Daundkar
Nov 14 '18 at 10:44





Thanks Alex... But is there any alternative to settimeout. Actually, i'm expecting actual value without settimeout.

– Mangesh Daundkar
Nov 14 '18 at 10:44













You need the actual value in the console? In the code it will always be the right value, if the array is empty then its length will always be 0. What you could do instead, is log a copy of the array so that the logged array and its length match. So change console.log(myArray) to console.log(myArray.slice()). Another option is to add a breakpoint in the "Sources" section of chrome devtools, where it will show the most recent value next to the variable name.

– Alex D
Nov 14 '18 at 11:00






You need the actual value in the console? In the code it will always be the right value, if the array is empty then its length will always be 0. What you could do instead, is log a copy of the array so that the logged array and its length match. So change console.log(myArray) to console.log(myArray.slice()). Another option is to add a breakpoint in the "Sources" section of chrome devtools, where it will show the most recent value next to the variable name.

– Alex D
Nov 14 '18 at 11:00




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297827%2farray-has-records-but-showing-array-length-0-in-console%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo