News for hackers. Stuff that matters.
Re:Silly Javascript by axod on Saturday July 25, 2009 @05:47PM (#723734)
>> "x is an Array (which should only accept numerics for keys). E.g. you cannot have a String be a "key" in an Array."

False. You can have anything you want in an Array, since it's just an object.

  var arr = [];
  arr["hello"] = 57;
  arr.world = function() {};
  arr[999.99] = "flibble!";
  arr[54] = 9;
  // arr.length now equals 55
May or may not be a good coding style, but that's a separate matter.
Re:Silly Javascript by invisible on Sunday July 26, 2009 @01:27AM (#724086)
Agreed, just in a rush to comment before. I'd go one further and say using an Array that way is just plain worrisome in JavaScript. It just breaks the conceptual usage "sort of" of Array vs Object (for/while vs for each...in). That's why a lot of frameworks add an "each" iterator for Array/Hashes (Hashes being a "controlled" Object added by most frameworks).