Array

From PlainOldWebserver

Jump to: navigation, search

Array()

Array is a strange creature. It is really derived from Object, giving it strange properties.


  <?sjs
    var a = new Array();
    a.push(4);
    a["dog"] = "Gus";
    document.writeln(" length is "+a.length);
    document.writeln(" a.dog is "+a.dog);
    document.writeln(" a[0] is "+a[0]);
  ?>

Here is the output.

  length is 1
  a.dog is Gus
  a[0] is 4

Using the Object properties, "dog" is added, but the length changes only with a push, assignment by index or the like. The apparent associative array is really an Object.

Personal tools
Navigation