-1

I have an array called gallery_list:

var gallery_list = ["profile.cfm", "explore.cfm", "list.cfm", "lesson.cfm", "class.cfm", "deploy_to_class.cfm"];

When I write the following, it works:

$.fancybox([
            { 'href' : gallery_list[0],
            'type' : 'iframe' },
            { 'href' : gallery_list[1],
            'type' : 'iframe' },
            { 'href' : gallery_list[2],
            'type' : 'iframe' },
            { 'href' : gallery_list[3],
            'type' : 'iframe' },
            { 'href' : gallery_list[4],
            'type' : 'iframe' },
            { 'href' : gallery_list[5],
            'type' : 'iframe' },

        ]);

But if I try to do something like below, it does not work:

var data = new Array();
        for (i = 0; i < gallery_list.length, i++) {
                var obj = {
                    'href' : gallery_list[i],
                    'type' : 'iframe'   
                }
                data.push(obj);
        }

$.fancybox([
            data
        ]); 

Can anyone provide any insight? Clearly I am getting something wrong with my data structures but I'm not sure what it is...

1

3 Answers 3

5

Your second example is an array inside an array. Instead:

$.fancybox(data);
Sign up to request clarification or add additional context in comments.

Comments

4

Can you try something like

$.fancybox( data ); 

Comments

0
$.fancybox([
            data
        ]);

Is redundant, data is already an array. [] is the operator for creating an array literal, so what you've done above is created an array, where the data array you've already constructed, is the first and only element.

As others have suggested what you want is the following:

$.fancybox(data);

To add a bit though, I think perhaps you would have avoided your mis-understanding had you initialized your "data" variable as follows:

var data = []; //instead of "new Array()"
for (i = 0; i < gallery_list.length, i++) {
    //etcetera

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.