how delete a particular element from an array
|
| View previous topic :: View next topic |
| Author |
Message |
Poolkop
Joined: 01 Jun 2006 Posts: 123
|
| How to delete a particular element from an array? |
| |
|
|
|
|
Gladis
Joined: 24 May 2006 Posts: 108
|
| Splice |
| |
|
|
autos06
Joined: 13 May 2006 Posts: 123 Location: New York
|
Poolkop, use delete
Delete myarray[3]; |
| |
|
|
Poolkop
Joined: 01 Jun 2006 Posts: 123
|
Splice works with index
I need to delete a random element each time |
| |
|
|
autos06
Joined: 13 May 2006 Posts: 123 Location: New York
|
Splice modifies the array indeces
Or at least the length property |
| |
|
|
Poolkop
Joined: 01 Jun 2006 Posts: 123
|
Mmm
Like say
I have three elementsi n an array
"yahoo", "msn", "google"
But their locations could be random
Msn could be first, yahoo could be 2nd and so on
Now how will i delete "msn" |
| |
|
|
AmeliaR
Joined: 31 May 2006 Posts: 142
|
| Using a temp array? |
| |
|
|
autos06
Joined: 13 May 2006 Posts: 123 Location: New York
|
| For (i=0; i<arr.length; i++) { if (arr[i] == 'msn') break; } delete arr[i]; (assuming that you know msn is in the array somewhere) |
| |
|
|
Poolkop
Joined: 01 Jun 2006 Posts: 123
|
| Ahh, ok, thanks |
| |
|
|
|
|