简体   繁体   中英

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 ?

Array.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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM