I use the following code for inserting data to json:
categories: [
'Tokyo',
'Jakarta',
'New York',
'Seoul',
'Manila',
'Mumbai',
'Sao Paulo',
'Mexico City',
'Dehli',
'Osaka',
'Cairo',
'Kolkata',
'Los Angeles',
'Shanghai',
'Moscow',
'Beijing',
'Buenos Aires',
'Guangzhou',
'Shenzhen',
'Istanbul'
],
It works, but, i want to put this data into an array or string variable like this:
var data = Array('Tokyo',
'Jakarta',
'New York',
'Seoul',
'Manila',
'Mumbai',
'Sao Paulo',
'Mexico City',
'Dehli',
'Osaka',
'Cairo',
'Kolkata',
'Los Angeles',
'Shanghai',
'Moscow',
'Beijing',
'Buenos Aires',
'Guangzhou',
'Shenzhen',
'Istanbul');
categories: [data],
But, It does not work. Can you help me ?
Thanks.
is already an array which is part of an object. if you want it as separate variable just create it like this:
and add it to your object
you could even do stuff like this:
but please use the bracket notation
hint: you are creating an “object literal” not a JSON-Object. JSON is just a subset of the object literal. read more here