cetver
cetver

Reputation: 11829

javascript: object property is array, but append isn't working

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 ?

Upvotes: 3

Views: 14478

Answers (2)

Joe
Joe

Reputation: 82594

Array.push:

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

should be:

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

Upvotes: 13

Madara's Ghost
Madara's Ghost

Reputation: 174957

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

Upvotes: 3

Related Questions