3
var objs = {
   'prop': []
}
objs['prop'].append('q');

Error: TypeError: objs.prop.append is not a function

Why this code is not working ?
Why console.log(typeof(objs['prop'])); is object not array ?

1
  • 2
    typeof is a red herring. (typeof new Array()) = "object" in Javascript. Commented Sep 27, 2011 at 17:26

2 Answers 2

13

Array.push:

var objs = {
   'prop': []
}
objs['prop'].append('q');

should be:

var objs = {
   'prop': []
}
objs['prop'].push('q');
Sign up to request clarification or add additional context in comments.

Comments

3

Because there are no associative arrays in JavaScript, an associative array is actually an Object. Nothing more nothing less.

2 Comments

Don't know how this is related to the question.
@JaredPar It is an answer to the second question, about why typeof an array returns "object"

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.