1 point

Creating a JSON Object in Javascript


dashboard

Posted by @infinitywars1_4k #javascript #json #objects #jsvariables

var eventsVariable = '"{events":[' +
    '{"location": "New York", "date": "May 1", "public": "true"},' +
    '{"location": "London", "date": "Apr 24", "public": "false"},' +
    '{"location": "San Frans", "date": "Nov 30", "public": "false"}]}';
    
content_copy Copy

When declaring an JSON object variable, you need to wrap the object in 'single commas like this'. Wrap each line in single commas and end line breaks with a plus sign. eventsVariable will look like this: {"events":[ {"location": "New York", "date": "May 1", "public": "true"}, {"location": "London", "date": "Apr 24", "public": "false"}, {"location": "San Frans", "date": "Nov 30", "public": "false"} ]}