Q:

Get JSON Object by string

I wrote a function which take an id of the link as a name of JSON dataset.
$('.link').click(function() {
    var dataset = $(this).attr("id");
    for (var i = 0; i < chart.series.length; i++) {
        chart.series[i].setData(lata.dataset[i].data);
    }
});

But in this case dataset is string and it doesn't works. So how to get object from JSON file by string?

A:

Use the [] operator:
chart.series[i].setData(lata[dataset][i].data);

foo['bar'] and foo.bar are equivalent - except the fact that [] takes an expression and thus allows you to use e.g.  a variable.

