The data you have provided is not valid JSON
. It should be enclosed in []
and use double quotes "
instead of single quotes '
:
var items = '[{"id": "10", "name": "item1"},{"id": "11", "name": "item2"}]';
To parse it, you can utilize:
var parsedItems = JSON.parse(items);
You can then access it using:
parsedItems[0].id
Keep in mind that this assumes the initial format of the data as a string represented in JSON
. If you are simply looking to create an array and access its elements, consider using an array literal like @bfavaretto mentioned.