Array String Indexes : String Indexer « Array « JavaScript Tutorial






It is possible to index arrays using strings.

To access an element, a string index value is placed into the [] operator.

<HTML>
<SCRIPT LANGUAGE="JavaScript">
<!--

    function populateArray(myArray) {
      myArray["A"]=4;
      myArray["B"]=2;
      myArray["C"]=1;
      myArray["D"]=5;
    }
    function displayArray(myArray){
      document.write(myArray['A']," A.<BR>");
      document.write(myArray['B']," B.<BR>");
      document.write(myArray['C']," C.<BR>");
      document.write(myArray['D']," pairs of D.");
    }
    var myArray = new Array();
    populateArray(myArray);
    displayArray(myArray);

-->
</SCRIPT>
</HTML>








11.7.String Indexer
11.7.1.Array String Indexes
11.7.2.Use string as the array indexer