0
rowData = [];

alert(rowData[0]);

gives me [Ti.UI.TableViewRow]

Now how can i remove this element... i have been using rowData.splice(), but i have no idea on what to pass to remove it.

Thanks

1
  • Note that removing it from the array won't remove it from the document, for this you need something like rowData[0].style.display = "none"; Commented May 1, 2011 at 12:31

3 Answers 3

2

In the code you present rowData should be empty, so rowData[0] should be undefined. I suppose something is pushed to rowData in between? Anyway, there are several ways to remove elements from arrays:

  • You can remove all elements at once from an array using rowData.length = 0.
  • If you want to remove 1 element, use the Array.splice method. E.g. removing the first element: rowData.splice(0,1) (means remove 1 element of rowData starting from element 0 (the first element).
  • If it's only the first element you want to remove you could also use the shift method: rowData.shift().
  • The last method you can use is slice: rowData = rowData.slice(1) (means: give me all elements from rowData starting at the first element and assign the result to rowData), or rowData.slice(1,4) (means: give me all elements from rowData starting at the first element, ending at the fourth element, and assign the result to rowData).
Sign up to request clarification or add additional context in comments.

Comments

2

try rowData.splice(0, 1); the first argument indicates the index of item to be removed, the second indicates how many items should be removed

Comments

1

If you want to remove the element(s) entirely, splice() will return a new array with the member(s) removed.

You can also use the delete operator, but this won't affect the Array size and the member will be undefined. This is will also make it non enumerable.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.