tags:

views:

22

answers:

2

I have a javasrcript variable

var hash = {
    '.bmp' : 1,
    '.gif' : 1,
    '.jpeg' : 1,
    '.jpg' : 1,
    '.png' : 1,
    '.tif' : 1,
    '.tiff' : 1,    
  };

I want to display the values (.bmp, .gif, .jpeg, .jpg, .png, .tif, .tiff) of this "hash" object in my alert message. How can I do this? Please help.

+1  A: 
var text ='',
for(key in hash)
    text += (key + ' = ' + hash[key] + '\n');

alert(text);

Although I must say what you're dealing with here is really an object that has properties that start with a dot, which seems like terribly bad practice to me. If they were without the dot, you could've done hash.bmp for instance, instead of hash['.bmp'].

David Hedlund
Awesome.... Thank you very much
A: 
alert(hash['.bmp']); //alerts 1

You might want to remove the trailing comma after the last item.

Amarghosh