1

is there a way for me to pass a variable name as a string in a function?

For example, I am trying to initialize a datatable by using a function that passes in variables for the datatable's attributes. Without using a function, I would initialize the table by:

TabularTables.myTable = new Tabular.Table({

    name: myTable

})

Instead, I want to initialize it with a function like:

function buildTable(tableName) = {

    TabularTables.tableName = new Tabular.Table({

        name: tableName

    })

}

And call it as:

buildTable('coolTableName');

However, when I try this, I get the error 'Your table is missing attributes'.

Can someone help?

Thanks!

Trung Tran
  • 13,141
  • 42
  • 113
  • 200
  • possible duplicate of [Dynamically access object property using variable](http://stackoverflow.com/questions/4244896/dynamically-access-object-property-using-variable) – Teemu Aug 03 '15 at 16:15

1 Answers1

2

Bracket notation should work (I haven't used the plugin):

TabularTables[tableName] = new Tabular.Table({
tymeJV
  • 103,943
  • 14
  • 161
  • 157