0

I want to create a dynamic Key Value Object in Java Script. Such as :

var resonseArray = [];
var i = 0;
      for (var key in value) { 
        if (value.hasOwnProperty(key)) { 
             finalObj = { i : {'keys': key , 'values' : value['key']}}};
             resonseArray.push(finalObj);
          i++;
        }
      }

But when I console the resonseArray, it console the i as a string not the dynamic variable i value.

RISHABH BANSAL
  • 140
  • 1
  • 2
  • 9

1 Answers1

0

you need to use bracket notation to create keys with variable

finalObj = {}
finalObj[i.toString()] = {'keys': key , 'values' : value['key']};
Easwar Raju
  • 253
  • 1
  • 4