Create a single array in which each element is a string containing both pieces of data, separated by a delimiter such as a colon (:) : Array Dimension « Array « Flash / Flex / ActionScript






Create a single array in which each element is a string containing both pieces of data, separated by a delimiter such as a colon (:)

 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){


        var aEmployees:Array = new Array();
        aEmployees.push("A:555-1234");
        aEmployees.push("P:555-4321");
        aEmployees.push("C:555-5678");
        aEmployees.push("H:555-8765");
        
        var aTempEmployeeInfo:Array = null;
        for(var i:Number = 0; i < aEmployees.length; i++) {
          aTempEmployeeInfo = aEmployees[i].split(":");
          trace("Employee:" + aTempEmployeeInfo[0]);
          trace("Phone Number:" + aTempEmployeeInfo[1]);
        }
    }
  }
}
Employee:A
Phone Number:555-1234
Employee:P
Phone Number:555-4321
Employee:C
Phone Number:555-5678
Employee:H
Phone Number:555-8765

        








Related examples in the same category

1.Working with Single-Dimension Arrays
2.Multidimensional Arrays
3.The idea behind parallel arrays is to create two (or more) arrays in which the elements with the same indices are related.
4.Working with Multidimensional Arrays
5.With multidimensional arrays, concat( ) or slice( ) only duplicates the top level of the array
6.Storing Complex or Multidimensional Data
7.Working with multiple sets of data: create a multidimensional array
8.Use nested for loop to deal with multiple sets of data
9.You can specify the properties of the object in any order you like
10.Creating an Associative Array
11.Create an associative array by adding properties to object
12.Compose dynamic properties
13.Two ways to add properties to dynamic object
14.Reading Elements of an Associative Array