Reputation: 39
Why is it giving this error when i surround the key with quotation marks?:
data[0].push({ "col" + (i+1): results.data[i].id});
Upvotes: 1
Views: 53
Reputation: 10396
Try using brackets (computed property name from ES6):
data[0].push({ ["col" + (i+1)]: results.data[i].id});
EDIT: If you are able to use ES6, you can also use template literal, as suggested by Ismael:
data[0].push({ [`col${i+1}`]: results.data[i].id});
Upvotes: 3