Passing string to function as an object's property in “let” gives “Unexpected token }”


New Member
I'm trying to make a 'generic' charting function which takes a series of parameters for charting different data values with different labels and baseline values. I've created the following function to handle this:
function ProcessChart(obj, valToChart, desc, element, baselineVal) {
    let arr = => {
        let { dateTime, [valToChart] } = e; // ERROR: Unexpected token }
        return [new Date(dateTime), +[valToChart]];

    arr.unshift(["DateTime", desc]);
    var data = google.visualization.arrayToDataTable(arr)

    var options = {
        title: desc + " for " + obj[0].computerName,
        curveType: 'function',
        legend: { position: 'bottom' },
        animation: {
            startup: false,
            duration: 500
        vAxis: {
            baseline: baselineVal,
            baselineColor: 'red'

    var chart = new
    chart.draw(data, options);
google.charts.setOnLoadCallback(ProcessChart(obj, "averageJitterInMs", "Average Jitter (ms)", "line-jitter-8hr", 10))
google.charts.setOnLoadCallback(ProcessChart(obj, "roundTripLatencyInMs", 'Round-Trip Latency (ms)', 'line-delay-8-hr', 8))
The problem is my valToChart being passed gives an error:
Unexpected token }
Is there another way I should be expressing this as a dynamic property on my obj object? I've tested this code with 'hard-coded' values in each place and it works fine.


Thành viên BQT
No destructuring required (it doesn't work that way anyway)
let arr = => [new Date(e.dateTime), +e[valToChart]]);
Should do what you want

Từ khóa phổ biến

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.