Reputation: 41
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.
Upvotes: 1
Views: 5147
Reputation: 59471
alert(hash['.bmp']); //alerts 1
You might want to remove the trailing comma after the last item.
Upvotes: 0
Reputation: 129832
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']
.
Upvotes: 2