user7186947
user7186947

Reputation: 39

Module build failed: SyntaxError: Unexpected token regarding quotation marks

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

Answers (1)

Alberto Trindade Tavares
Alberto Trindade Tavares

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

Related Questions