I am in need to set a JS object property name dynamically.
for(i=1; i<3; i++) { var key = i+'name'; data = { key : 'name1', } }
Result should be:
data = { 1name: 'name1' 2name: 'name1' }
var jsonVariable = {}; for(var i=1; i < 3; i++) { jsonVariable[i + 'name'] = 'name' + i; }
1.4m articles
1.4m replys
5 comments
57.0k users