1

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.

2 Answers 2

2
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'].

Sign up to request clarification or add additional context in comments.

Comments

0
alert(hash['.bmp']); //alerts 1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.