Object.keys returns an empty array for an object containing properties











up vote
0
down vote

favorite












My project contains an ES6 class whose constructor is defined as follows:



  constructor() {
this.campaignName = 'United Way';
this.campaign = {};
this.questions = {};
this.benefits = {};
this.assistors = {};
this.locations = {};
this.buildDataObjects = this.buildDataObjects.bind(this);
this.retrieve();
}


Later in the code, the properties with default values of empty objects are given new values using Object.assign; however, I do not believe that code has any relevance for solving the problem at hand, so it is not included.



Elsewhere in the project's codebase, an instance of the class is being output using console.info:



enter image description here



As evident from the screenshot, there is seemingly nothing unusual about the object.



Next, the object's "questions" property is output:



enter image description here



The first line in the screenshot is an empty object, even though the output below includes the object's properties. However, those properties are inaccessible, as evident by the fact that calling Object.keys with the given object produces an empty array.



enter image description here



I am at a total loss as to the cause of this behavior and would appreciate some insight. Thanks in advance!










share|improve this question






















  • The fact that the object shows as {} and afterwards has elements tells you that the questions only exist after you log them in the console. Hence the how and when the "questions" are generated/assigned does matter.
    – Andreas
    Nov 22 at 17:36










  • Interesting...the second line is part of the same console.info output so how can they only exist after they're logged?
    – Boris Layvant
    Nov 22 at 17:40






  • 1




    Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference
    – Andreas
    Nov 22 at 17:44










  • @Andres you are correct. It turns out that the assignment of a new value for questions was taking place after console.info was called.
    – Boris Layvant
    Nov 22 at 18:05















up vote
0
down vote

favorite












My project contains an ES6 class whose constructor is defined as follows:



  constructor() {
this.campaignName = 'United Way';
this.campaign = {};
this.questions = {};
this.benefits = {};
this.assistors = {};
this.locations = {};
this.buildDataObjects = this.buildDataObjects.bind(this);
this.retrieve();
}


Later in the code, the properties with default values of empty objects are given new values using Object.assign; however, I do not believe that code has any relevance for solving the problem at hand, so it is not included.



Elsewhere in the project's codebase, an instance of the class is being output using console.info:



enter image description here



As evident from the screenshot, there is seemingly nothing unusual about the object.



Next, the object's "questions" property is output:



enter image description here



The first line in the screenshot is an empty object, even though the output below includes the object's properties. However, those properties are inaccessible, as evident by the fact that calling Object.keys with the given object produces an empty array.



enter image description here



I am at a total loss as to the cause of this behavior and would appreciate some insight. Thanks in advance!










share|improve this question






















  • The fact that the object shows as {} and afterwards has elements tells you that the questions only exist after you log them in the console. Hence the how and when the "questions" are generated/assigned does matter.
    – Andreas
    Nov 22 at 17:36










  • Interesting...the second line is part of the same console.info output so how can they only exist after they're logged?
    – Boris Layvant
    Nov 22 at 17:40






  • 1




    Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference
    – Andreas
    Nov 22 at 17:44










  • @Andres you are correct. It turns out that the assignment of a new value for questions was taking place after console.info was called.
    – Boris Layvant
    Nov 22 at 18:05













up vote
0
down vote

favorite









up vote
0
down vote

favorite











My project contains an ES6 class whose constructor is defined as follows:



  constructor() {
this.campaignName = 'United Way';
this.campaign = {};
this.questions = {};
this.benefits = {};
this.assistors = {};
this.locations = {};
this.buildDataObjects = this.buildDataObjects.bind(this);
this.retrieve();
}


Later in the code, the properties with default values of empty objects are given new values using Object.assign; however, I do not believe that code has any relevance for solving the problem at hand, so it is not included.



Elsewhere in the project's codebase, an instance of the class is being output using console.info:



enter image description here



As evident from the screenshot, there is seemingly nothing unusual about the object.



Next, the object's "questions" property is output:



enter image description here



The first line in the screenshot is an empty object, even though the output below includes the object's properties. However, those properties are inaccessible, as evident by the fact that calling Object.keys with the given object produces an empty array.



enter image description here



I am at a total loss as to the cause of this behavior and would appreciate some insight. Thanks in advance!










share|improve this question













My project contains an ES6 class whose constructor is defined as follows:



  constructor() {
this.campaignName = 'United Way';
this.campaign = {};
this.questions = {};
this.benefits = {};
this.assistors = {};
this.locations = {};
this.buildDataObjects = this.buildDataObjects.bind(this);
this.retrieve();
}


Later in the code, the properties with default values of empty objects are given new values using Object.assign; however, I do not believe that code has any relevance for solving the problem at hand, so it is not included.



Elsewhere in the project's codebase, an instance of the class is being output using console.info:



enter image description here



As evident from the screenshot, there is seemingly nothing unusual about the object.



Next, the object's "questions" property is output:



enter image description here



The first line in the screenshot is an empty object, even though the output below includes the object's properties. However, those properties are inaccessible, as evident by the fact that calling Object.keys with the given object produces an empty array.



enter image description here



I am at a total loss as to the cause of this behavior and would appreciate some insight. Thanks in advance!







javascript ecmascript-6






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 at 17:28









Boris Layvant

287




287












  • The fact that the object shows as {} and afterwards has elements tells you that the questions only exist after you log them in the console. Hence the how and when the "questions" are generated/assigned does matter.
    – Andreas
    Nov 22 at 17:36










  • Interesting...the second line is part of the same console.info output so how can they only exist after they're logged?
    – Boris Layvant
    Nov 22 at 17:40






  • 1




    Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference
    – Andreas
    Nov 22 at 17:44










  • @Andres you are correct. It turns out that the assignment of a new value for questions was taking place after console.info was called.
    – Boris Layvant
    Nov 22 at 18:05


















  • The fact that the object shows as {} and afterwards has elements tells you that the questions only exist after you log them in the console. Hence the how and when the "questions" are generated/assigned does matter.
    – Andreas
    Nov 22 at 17:36










  • Interesting...the second line is part of the same console.info output so how can they only exist after they're logged?
    – Boris Layvant
    Nov 22 at 17:40






  • 1




    Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference
    – Andreas
    Nov 22 at 17:44










  • @Andres you are correct. It turns out that the assignment of a new value for questions was taking place after console.info was called.
    – Boris Layvant
    Nov 22 at 18:05
















The fact that the object shows as {} and afterwards has elements tells you that the questions only exist after you log them in the console. Hence the how and when the "questions" are generated/assigned does matter.
– Andreas
Nov 22 at 17:36




The fact that the object shows as {} and afterwards has elements tells you that the questions only exist after you log them in the console. Hence the how and when the "questions" are generated/assigned does matter.
– Andreas
Nov 22 at 17:36












Interesting...the second line is part of the same console.info output so how can they only exist after they're logged?
– Boris Layvant
Nov 22 at 17:40




Interesting...the second line is part of the same console.info output so how can they only exist after they're logged?
– Boris Layvant
Nov 22 at 17:40




1




1




Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference
– Andreas
Nov 22 at 17:44




Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference
– Andreas
Nov 22 at 17:44












@Andres you are correct. It turns out that the assignment of a new value for questions was taking place after console.info was called.
– Boris Layvant
Nov 22 at 18:05




@Andres you are correct. It turns out that the assignment of a new value for questions was taking place after console.info was called.
– Boris Layvant
Nov 22 at 18:05












1 Answer
1






active

oldest

votes

















up vote
0
down vote













As @Andreas pointed out, the console output was being performed before the assignment of a new value to "questions" was completed.



enter image description here



As a side-note, my confusion was exacerbated by the presence of properties below the empty object in the console output, which are apparently somehow appended after the fact.






share|improve this answer





















  • You should hover over the blue bloxed i.
    – Felix Kling
    Nov 22 at 19:33











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',
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%2f53435852%2fobject-keys-returns-an-empty-array-for-an-object-containing-properties%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








up vote
0
down vote













As @Andreas pointed out, the console output was being performed before the assignment of a new value to "questions" was completed.



enter image description here



As a side-note, my confusion was exacerbated by the presence of properties below the empty object in the console output, which are apparently somehow appended after the fact.






share|improve this answer





















  • You should hover over the blue bloxed i.
    – Felix Kling
    Nov 22 at 19:33















up vote
0
down vote













As @Andreas pointed out, the console output was being performed before the assignment of a new value to "questions" was completed.



enter image description here



As a side-note, my confusion was exacerbated by the presence of properties below the empty object in the console output, which are apparently somehow appended after the fact.






share|improve this answer





















  • You should hover over the blue bloxed i.
    – Felix Kling
    Nov 22 at 19:33













up vote
0
down vote










up vote
0
down vote









As @Andreas pointed out, the console output was being performed before the assignment of a new value to "questions" was completed.



enter image description here



As a side-note, my confusion was exacerbated by the presence of properties below the empty object in the console output, which are apparently somehow appended after the fact.






share|improve this answer












As @Andreas pointed out, the console output was being performed before the assignment of a new value to "questions" was completed.



enter image description here



As a side-note, my confusion was exacerbated by the presence of properties below the empty object in the console output, which are apparently somehow appended after the fact.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 at 18:15









Boris Layvant

287




287












  • You should hover over the blue bloxed i.
    – Felix Kling
    Nov 22 at 19:33


















  • You should hover over the blue bloxed i.
    – Felix Kling
    Nov 22 at 19:33
















You should hover over the blue bloxed i.
– Felix Kling
Nov 22 at 19:33




You should hover over the blue bloxed i.
– Felix Kling
Nov 22 at 19:33


















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f53435852%2fobject-keys-returns-an-empty-array-for-an-object-containing-properties%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

What visual should I use to simply compare current year value vs last year in Power BI desktop

Alexandru Averescu

Trompette piccolo