1

I want to do this using literals:

newObject.object[0].time = 1200;

But the following code gives an error:

var newObject = {
    object[0].time: 1200
};

Is there any way to construct such an objects using literals?

1 Answer 1

3
var newObject = {        // base object
    object: [            // array as "newObject.object"
        {                // object as a first element of array
            time: 1200
        }
    ]
};

console.log(newObject.object[0].time);  // 1200
Sign up to request clarification or add additional context in comments.

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.