JavaScript bracket notation allows you to use strange variable names
by Cory Rauch 2009-01-21 Category: JavaScript

And you wonder why you would want to do that? Well, at times using invalid characters in variables names maybe unavoidable. Take the example below:

<form name="test" . . . >
<input type="text" name="items[]" />
<input type="text" name="items[]" />
</form>

The above example in PHP would return an array called "items" when the above form was posted. This is desired in certain circumstances, but how would you access those form elements in JavaScript? With bracket notation you can do this by using the code:

var items = document.forms["test"].elements["items[]"];

Anther example of usage maybe accessing variables where you are dynamically generating the variables name, example:

var setting_1 = "test";
var setting_2 = "test 2";
var setting_3 = "test 3";
for(var a=1; a < 4; a++) {
	document.write(window["setting_"+a] + '<br>');
}

Other ImprovedSource Articles:
How to detect if your in a frame via JavaScript
How to do custom sorting in Javascript on arrays
Free JavaScript Solitaire Game

Valid HTML 4.01 Transitional