Javascript examples for Array Operation:Array Index
Use a variable for the index of an array
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/* w ww .j a va 2 s.co m*/ var arr = ['first', 'second', 'third']; var value = document.getElementsByTagName('span')[0].innerHTML; console.log(typeof value); console.log(arr[value]); } </script> </head> <body> <span>1</span> </body> </html>