-2

I have an object of objects as follows:

var people = {
"fred": {"height": 10, "weight": 190},
"mary": {"height": 6, "weight": 120}
};

I want to add another item to this object. Specifically, I want to add the following object:

var luke = {"height": 8, "weight": 130};

Why can't I just do so using people.push? such as:

people.push(luke)
2
  • Alternate answer: people.luke = luke Commented May 17, 2016 at 1:15
  • 1
    The answer is that push() is a method for arrays, and you don't have any arrays, only objects. Commented May 17, 2016 at 1:16

1 Answer 1

1

You should do

 people["luke"] = luke

or

 people.luke = luke
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.