var arr ={count:12,total:110};
console.log(arr.count,'',arr.total) //12 110
但是如何使用这样
var c='count';
console.log(arr.c) //it's not similar to arr.count is there is any way to use this
如何通过引用字符串来访问数组对象?
答案 0 :(得分:1)
var c='count';
console.log(arr[c])
您可以使用括号表示法访问键/属性
答案 1 :(得分:1)
var arr ={count:12,total:110};
var c='count';
console.log(arr[c],'',arr.total) //12 110

答案 2 :(得分:0)
试试这个
var c = arr['count'];