0

I'm trying to iterate through this array to pins on a map, in every browser it seems to work fine but in IE8 I get the error "SCRIPT5007: Unable to get value of the property 'top': object is null or undefined" If I change top to something else or remove it, IE just says the same thing about left or name, etc. If anyone had any suggestions, they would be greatly appreciated.

jQuery(document).ready(function(){
    var pins =  [
            { "name":"Mexico", "top":"154" , "left":"176", "imageFile":"Mexico.jpg", "soundMP3File":"Mexico_GMartinez_1.mp3", "soundOGGFile":"Mexico_GMartinez_1.ogg"},
            { "name":"Chile", "top":"261" , "left":"246", "imageFile":"Chile.jpg", "soundMP3File":"Chile_MVelasquez_1.mp3", "soundOGGFile":"Chile_MVelasquez_1.ogg"},
            { "name":"Trinidad and Tobago", "top":"182" , "left":"242", "imageFile":"TrinidadTobago.jpg", "soundMP3File":"Trinidad-Tobago_SHarris_1.mp3", "soundOGGFile":"Trinidad-Tobago_SHarris_1.ogg"},
            { "name":"Columbia", "top":"209" , "left":"227", "imageFile":"Columbia.jpg", "soundMP3File":"Colombia_JGordon_2.mp3", "soundOGGFile":"Colombia_JGordon_2.ogg"},
            { "name":"Canada", "top":"86" , "left":"208", "imageFile":"Canada.jpg", "soundMP3File":"Canada_KBretzer_1.mp3", "soundOGGFile":"Canada_KBretzer_1.ogg"},            
            ];

for(var i = 0; i < pins.length; i++)
    {
        jQuery('#map #pins-container').append('<a href="#" class="pin" style="top: ' + pins[i].top + 'px; left:' + pins[i].left + 'px;" pinindex="' + i + '" name="' + pins[i].name + '"></a>');
    }


});
1
  • 5
    You have a trailing comma after the last object in the array. Remove that. Commented Feb 25, 2013 at 14:51

2 Answers 2

3

@Guffa is right. The trailing comma on the 'Canada' line is invalid.

IE is the only browser that will actually complain abuot it, but it is techinically invalid everywhere.

In order to avoid issues like this, you should use tools like JSHint, which will validate your Javascript code for coding common errors, including the trailing comma bug.

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

1 Comment

Note: JShint is integrated into JSfiddle.net. I recomment you to go that way.
0

In IE If you give comma after last JSON object this is give error in IE6,IE7,IE8.

So, Always remember this When ever you are writing Javascript,JSON

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.