Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I receive an error of 'mydoc.docMeta is undefined' when I try to do this:
var mydoc = {}; mydoc.docMeta.keyword = "somevalue";
What am I doing wrong?
Since mydoc.docMeta is also an object, you have to define it first:
mydoc.docMeta
var mydoc = {}; mydoc.docMeta = {}; mydoc.docMeta.keyword = "somevalue";
Or just use a literal:
var mydoc = { docMeta : { keyword : "somevalue" } };
Add a comment
You have to nest one more level:
var mydoc = { docMeta: { keyword: "somevalue" } }
Do you want docMeta to be another object literal?
docMeta
var mydoc = { docMeta: {} };
Try
var mydoc = {}; mydoc.docMeta = { keyword : "somevalue" };
You are declaring mydoc as an object, but then you are trying to set an attribute of an attribute of an object, first you have to declare that attribute as an object as well
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.