Reputation:
I have the following code:
oTable.fnSort([[columnIndex, 'asc']]);
Can someone explain to me what the ([[]]) means. I have never seen brackets inside of brackets before.
Upvotes: 0
Views: 562
Reputation: 165941
You're passing an array to the fnSort
method. That array contains one element, which happens to be another array, with two elements:
[] // An empty array
[[]] // An array with one element (an empty array)
[[columnIndex, "asc"]] // An array with one element (an array with 2 elements)
This is known as array literal syntax, which is generally preferred to the alternative (the Array
constructor).
Upvotes: 4
Reputation: 437336
Square brackets are notation for a JavaScript array. This code means that the argument to the function is an array that contains one element, which is an array itself.
An array with two elements:
[columnIndex, 'asc']
An array with one element, which is an array that contains two elements:
[[columnIndex, 'asc']]
Upvotes: 3