jeudi 4 août 2016

Finding index using switch case statement in javascript

For example this is my table structure

 +--------+--------+--------+
| RLD    | MD     | INC    |
+--------+--------+--------+
|      0 |   3868 | 302024 |
|  53454 |   7699 | 203719 |
| 154508 |    932 |  47694 |
| 107547 |  36168 |  83592 |

I want to use a script which would give me the max_value and its index number,such that my output would look like

+--------+--------+--------+-----------+-----------+
| RQD    | MT     | IZC    | max_value | max_index |
+--------+--------+--------+-----------+-----------+
|      0 |   3868 | 302024 |    302024 |         3 |
|  53454 |   7699 | 203719 |   203719  |         3 |
| 154508 |    932 |  47694 |    154508 |         1 |
|    456 |  107547|  83592 |    107547 |         2 |

To get the max value from rows I have used

var max_value = Math.max(RQD,MT,IZC);
println(max_value);

I tried to get their index using following script

var max_index = switch (Math.max(RQD,MT,IZC))
           {
           case "RQD":document.write("1")
           case "MT":document.write("2")
           case "MT":document.write("3")
         default:document.write("0") 

       }

how can I get the desired result, any help would be much appreciated.Thanks

Aucun commentaire:

Enregistrer un commentaire