10-29-2009, 10:11 PM
|
#1
|

 |
The middle of frickin nowhere |
|
 |
75 |
|
|
Cleaning empty array elements
So I have an array that when traced, lets say looks like
ActionScript Code:
Carrot,Apple,Strawberry,,,Cantaloupe
I'm just wondering, what's the best way to tell if an element in an array is empty?
__________________
www.ExperimentalFlash.com - Crappy games, crappy toons, and other crappy stuff. Take a few minutes out of your crappy day to go there  .
|
|
|
10-29-2009, 10:47 PM
|
#2
|
|
|
ActionScript Code:
var a:Array = [1, null, undefined, {}.a, 3, 0/0, Infinity, -Infinity, 5];
for(var i:Number = 0; i < a.length; i++){ if(a[i] == undefined){ trace('a[' + i + '] (' + a[i] + ') is unstrictly equal to undefined'); } }
|
|
|
10-30-2009, 07:50 AM
|
#3
|
|
|
And to remove the empty ones:
ActionScript Code:
var a:Array = ["apple", null, "banana", "", "orange", "", undefined, "grape"];
for ( var i:Number = 0; i < a.length; i++ ) { if ( !a[i] ) a.splice(i, 1); }
trace(a.join(", "));
__________________
AS / JS / HTML / CSS / PHP
|
|
|
10-30-2009, 11:47 AM
|
#4
|

 |
Halley Research Station,
Latitude 75°35' S,
Longitude 26°39' W,
Brunt Ice Shelf,
Coats Land,
Antarctica |
|
 |
4,158 |
|
|
I'd suggest a slight amendment, just to take care of those pesky consecutive occurences of empty elements, e.g. "apple", null, null, "banana", "", "", "", "orange", "", undefined, "grape":
__________________
©2006 GlosRFC - Searching 8,168,684,336 brain cells
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 01:45 PM.
|
|