Reputation: 15044
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
Upvotes: 0
Views: 225
Reputation: 122986
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:
rowData.length =
0
.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).shift
method: rowData.shift()
.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
).Upvotes: 2
Reputation: 490597
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.
Upvotes: 1
Reputation: 12425
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
Upvotes: 3