意想不到的 JavaScript Array


1
2
3
4
5
6
7
8
9
<script language="javascript" type="text/javascript">
var myArray = [ 3, 'hello!', function() {return 5}, {'color':'blue', 'budget':25}, /[ell]/i ];
document.writeln('0>'+myArray[0]+'<BR>'); // Will output: 0>3
document.writeln('1>'+myArray[1]+'<BR>'); // Will output: 1>hello!
document.writeln('2>'+myArray[2]()+'<BR>'); // Will output: 2>5
document.writeln('3>'+myArray[3].color+'<BR>'); // Will output: 3>blue
document.writeln('3>'+myArray[3].budget+'<BR>'); // Will output: 3>25
document.writeln('4>'+myArray[4].test(myArray[1])+'<BR>'); // Will output: 4>true
</script>