Array has records but showing array length 0 in console
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,
Every time when i add new file, the length getting in console is (actual length -1)
arrays angular console
add a comment |
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,
Every time when i add new file, the length getting in console is (actual length -1)
arrays angular console
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
add a comment |
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,
Every time when i add new file, the length getting in console is (actual length -1)
arrays angular console
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,
Every time when i add new file, the length getting in console is (actual length -1)
arrays angular console
arrays angular console
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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