Javascript eval Function

by Francis 2013-07-17 14:57:52

Javascript eval Function
This function evaluates or executes an argument. In array how we executes dynamically.


Example
<script>
function test()
{
var ary1 = new Array("1", "2", "3", "4", "5", "6", "7", "8", "9");
var ary2 = new Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
var aryname = $("#arrs").val();
alert(aryname.length);
alert(eval(aryname).length);
}
</script>

<html>
<select id="arrs" onchange="test()"> <option value="ary1"> Numbers </option> <option value="ary2"> Alphabets </option> </select>
</html>

Result
1) If select Numbers == >
i) First alert result is 4
Because, to calculate the option value length.
ii) Second alert result is 9
Because, its execute the value and refer to the array variable name then to calculate the array length.

Similarly,
2) If select Alphabets == >
i) First alert result is 4
ii) Second alert result is 26



603
like
0
dislike
0
mail
flag

You must LOGIN to add comments