0 Replies - 216 Views - Last Post: 27 February 2005 - 01:54 AM

#1 Broly  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 16-December 04

Array.noEmpty()

Posted 27 February 2005 - 01:54 AM

Description: //Usage sample arr= new Array("","Hello","Friend","", "Hello","","World") trace("Original array: " + arr) //Trace original array trace("Cleaned array: " + arr.clean("")) // Trace cleaned array (delete empty values) //trace("Cleaned array : " + arr.clean("Hello")) // Trace cleaned array (delete "Hello" values) // by Davide Beltrame (Broly) // e-mail: [email protected] // // This function remove the empty element // from an array
// ---------------------------------------
//             Array.clean 
//           prototype function
// 
// by Davide Beltrame (Broly)
// e-mail: [email protected]
// 
// This function remove the empty element 
// from an array
//
// Syntax
//
// arrayname.clean(to_delete)
//
// Parameter: to_delete <- element to delete from the array
// 
// ----------------------------------------
Array.prototype.clean = function(to_delete)
{
   var a;
   for (a = 0; a < this.length; a++)
   {
      if (this[a] == to_delete)
      {         
         this.splice(a, 1);
         a--;
      }
   }
   return this;
};

//Usage sample
arr= new Array("","Hello","Friend","", "Hello","","World")
trace("Original array: " + arr) //Trace original array
trace("Cleaned array: " + arr.clean("")) // Trace cleaned array (delete empty values)
//trace("Cleaned array : " + arr.clean("Hello")) 
// Trace cleaned array (delete "Hello" values) 


Is This A Good Question/Topic? 0
  • +

Page 1 of 1