0

I have Array in this format.

rowData[0] = addRow(aa);        
rowData[1] = addRow(aaa);        
rowData[2] = addRow(aa);        
rowData[3] = addRow(aa);    

addRow is a function which gets this value process.But i don't want to give the Array Index, instead i want to give rowData[i], then put in a loop and access the elements.

rowData holds the an object which addRow returns.

var data = [rowData];
var table = Ti.UI.createTableView({
        data:data
});

4 Answers 4

2

Use the Array.push function to store the data:

rowData.push(addRow(aa));  
rowData.push(addRow(aaa));  
.
.
.
.
.

Another alternative is:

rowData[rowData.length] = addRow(aa);  
rowData[rowData.length] = addRow(aaa);  
.
.
.
.
.

Use the regular index based iterations to get the data:

for(var i=0; i< rowData.length; i++){
  var curItem = rowData[i];
}
Sign up to request clarification or add additional context in comments.

Comments

1
for (var i = 0; i < rowData.length; i++)
{
    rowData[i] = addRow(aa);
}

1 Comment

You've not been clear with what the difference is between addRow(aa) and addRow(aaa) and how that relates to the array index...
1

did u mean this?

var rowData = {};
rowData[aa] = addRow(aa);
rowData[aaa] = addRow(aaa); 

for loop access

for(var index in rowData){
  var data = rowData[index]
  ...
}

Comments

1

A loop may not be feasible in your case. This may be an idea: you can rewrite the Array.push prototype method:

Array.prototype._push = Array.prototype.push;
Array.prototype.push = function(val){ this._push(val); return this;};

After which you can chain the push operations:

rowData.push(addRow(aa))
       .push(addRow(aaa))        
       .push(addRow(aa))        
       .push(addRow(aa)); 

But actually, it looks like you are mixing arrays with objects. Here's an answer I formulated earlier on that subject.

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.