1

I may be looking at this one the wrong way. I think that dynamically naming the object is the difficult part rather than creating it.

Basically I have an array of arrays and I want to get the nested arrays out.

var $jTableTRS = $('tr.child');
var $jTableTRSArr = jQuery.makeArray($jTableTRS);

each slot in $jTableTRSArr has an array object contained. Thing is i will never know how many arrays are in the $jTableTRSArr.

for(var i=0;i<$jTableTRSArr.length;i++)
    {
            //var  tempArray(withuniqueidentifier) = $jTableTRSArr[i]
    }

This means I could reference each nested array by its name like

tempArray1[0].variable
and not $jTableTRSArr[0].variable.

I'm essentially bringing the nested arrays up one level.

Can this be done or is there a better way to do it?

2
  • If you say you will not know how many arrays are into $jTableTRSArr how would you know which intex to use in your variable? And what is wrong using $jTableTRSArr.length to know how many arrays are there? Commented Aug 12, 2011 at 15:12
  • I mean I will never know before the for loop. Basically Its a table with editable columns. Each nested array is a row. I will know how many default elements there are but not any extras they added on. And i don't know what index they will use, I will have to use something like i to name them. Commented Aug 12, 2011 at 15:18

1 Answer 1

1

To create dynamic variable names, you could do:

for (var i = 0; i < arr.length; i++){
    window['MyNewArray-' + i] = arr[i];
}

Is this what you were looking for?

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

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.