0
var arr ={count:12,total:110};
console.log(arr.count,'',arr.total)   //12 110

but how to use like this

var c='count';
console.log(arr.c) //it's not similar to arr.count is there is any way to use this

How to access the array object by referring to the string?

Vickey
  • 365
  • 1
  • 3
  • 17

3 Answers3

1
var c='count';
console.log(arr[c])

You can access the key/properties using bracket notation

Isaac
  • 12,042
  • 16
  • 52
  • 116
1

var arr ={count:12,total:110};
var c='count';

console.log(arr[c],'',arr.total)   //12 110
Mohamed Abbas
  • 2,228
  • 1
  • 11
  • 19
0

Try this

var c = arr['count'];
n1md7
  • 2,854
  • 1
  • 12
  • 27