Initializing an Associative Array in Javascript

Ian presented the following question to me: How do you initialize an associative array with default values in javascript? There is plenty of posts out there on the internet in regards to creating arrays, most look something like:

var myArray = new Array();
myArray["something"] = "some value";


and so on. But what he was looking for was something more like the php method:

$myArray = ( "something"=> "some value", "something else" => "another value");

after a small amount of scouring remembering something about colons, I finally found a scathing post by someone with the revelation: Javascript doesn't actually have associative arrays. In fact javascript doesn't have arrays at all. It has objects. So how do you initialize an associative array in javascript? You don't. You initialize an object:

var arrayTest = {"something":"1st Result","second":"2nd Result"};
alert(arrayTest["second"]);


Hopefully that helps someone out there in Google land.

Javascript Variable Variables

Looking for a way to dynamically generate and assign variable names to objects in javascript, I found this post on creating a sort of variable variable in Javascript. Reading the post itself, I found the answer to my immediate question. However upon reading the comments, I feel like I had a moment of clarity in my understanding of the truly awesome power of javascript, dot notation, and prototype. Why is javascript so underestimated? I see this changing in the very near future...

http://www.i-marco.nl/weblog/archive/2007/06/14/variable_variables_in_javascri

PHP getimagesize()

Wondering how to find out the size of your image? getimagesize() returns a lovely array containing the height and width of the image, along with a few other bits of data. In fact, one of the array values is even a nice little string containing height="yyy" width="xxx" that can be used directly in an IMG tag.

See the php manual entry for more info on this, as well as a number of other nifty image data gathering functions.

PHP ini_get

A somewhat useful function in PHP - ini_get(string $varname). Useful for troubleshooting, would have come in handy for me once or twice in the past when trying to prove to a server admin that globals were on or off. IE:

echo 'register_globals = ' . ini_get('register_globals') . "\n";

Returns something like:
register_globals = 0
Read the PHP Manual entry for more details.