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
?
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
?
- 2 typeof is a red herring. (typeof new Array()) = "object" in Javascript. – Elliot Nelson Commented Sep 27, 2011 at 17:26
2 Answers
Reset to default 13Array.push:
var objs = {
'prop': []
}
objs['prop'].append('q');
should be:
var objs = {
'prop': []
}
objs['prop'].push('q');
Because there are no associative arrays in JavaScript, an associative array is actually an Object. Nothing more nothing less.