0

Can someone please tell me what this javascript code does? I came across it in a jQuery routine to select table rows.

Each of the following can range from -1 to the table-row count -1:

  • lastIndex is the row number of the last-seleted row.
  • thisIndex is the row number of the currently-selected row.

Code:

thisIndex = [lastIndex, lastIndex = thisIndex][0] ; 

Help!

jarmod
  • 71,565
  • 16
  • 115
  • 122
PaulJayD
  • 175
  • 1
  • 1
  • 9

1 Answers1

0

This is one method to swap the two values inside the variables thisIndex and lastIndex without using a temporary variable.

On the RHS, there is an array of two values and [0] will return the first value.

example: Suppose

thisIndex  = 10;
lastIndex = 20;

[lastIndex, lastIndex = thisIndex]

will become

[20,10]

and then assign 20 to lastIndex, the expression returns 10 which is assigned to thisIndex

midhunhk
  • 5,560
  • 7
  • 52
  • 83