0

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?

4 Answers 4

3

Since mydoc.docMeta is also an object, you have to define it first:

var mydoc = {};
mydoc.docMeta = {};
mydoc.docMeta.keyword = "somevalue";

Or just use a literal:

var mydoc = {
    docMeta : {
        keyword : "somevalue"
    }
};
Sign up to request clarification or add additional context in comments.

Comments

2

You have to nest one more level:

var mydoc = {
   docMeta: {
       keyword: "somevalue"
   }
}

Comments

1

Do you want docMeta to be another object literal?

var mydoc = { docMeta: {} };

Comments

1

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

Comments

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.