Hatem
Hatem

Reputation: 589

TypeError when using mutli-dimensional array on JavaScript

I got this error on firefox errors debugger :

Error: TypeError: slidesArray[index] is undefined Source File: http://mydomain.com/hatem/scripts/slider.js

The code is built on jQuery as you see :

    jQuery.each
    (
        slidesArray,function(index,value)
        {
            $("#slider").show();

            var linkHref = slidesArray[index][1];
            var imageSource = slidesArray[index][0];
            alert(imageSource)
            $("#slider").html
            (
                "<a href='" + linkHref + "'><img src='"+ imageSource + "'></a>"
            ).hide().fadeIn(5000);

            $("#slider").hide();
        }
    );

Notes : The Array slidesArray checked by me and it is exist with several elements.

Thanks

Upvotes: 1

Views: 424

Answers (1)

Diode
Diode

Reputation: 25165

Check the array slidesArray. Try this to find out which index is undefined

jQuery(slidesArray).each(function(index, value) {
    if (value && value.length) {
        $("#slider").show();

        var linkHref = value[1];
        var imageSource = value[0];
        alert(imageSource)
        $("#slider").html("<a href='" + linkHref + "'><img src='" + imageSource + "'></a>").hide().fadeIn(5000);

        $("#slider").hide();
    } else {
        alert("slidesArray[" + index + "] is invalid");
    }
});

Upvotes: 1

Related Questions