News for hackers. Stuff that matters.
Re:Silly Javascript by axod on Saturday July 25, 2009 @05:03PM (#723667)
Read a book on javascript.

"Javascript: The definitive guide" by O'Reily is the best.

This is not a quirk, Arrays are just objects with a special property 'length' which is set to the highest key that can be converted to an integer, plus one, and the array functions. All keys are however, strings, as with all objects.

For example,

  var arr = [];
  arr.foo = "hello";
  arr["hello"] = function() {};
  arr[40] = 56;
  // arr.length = 41
It's much easier when you understand that arrays in javascript don't exist as a separate data type. They are, as I say, just objects with a couple of convenience methods+length property.

There are no comments on this comment yet.