News for hackers. Stuff that matters.
Re:Fun with JavaScript Arrays by cema on Wednesday June 12, 2013 @09:53AM (#5868047)
Not just the length property, but also a special array API (push, pop, etc). So there is no equivalence between an array and the simple object constructed from its keys and values, but the object would correctly represent a snapshot of the subset of array key-value pairs.
Re:Fun with JavaScript Arrays by jdlshore on Wednesday June 12, 2013 @10:21AM (#5868195)
Technically, the special API is because arrays extend Array.prototype. You could create an object that does the same, and push(), pop(), etc would work.*

Try going to http://www.objectplayground.com and putting in the following code, selecting the "Show built-in objects" option, and evaluating:

  this.array = [];
  this.object = Object.create(Array.prototype);

  this.object.push("foo");
  this.object.push("bar");
*Well, they sort of work. They use and modify the "length" property, so you could see some weird behavior under some circumstances. Not recommended for production use. :-)
Re:Fun with JavaScript Arrays by cema on Wednesday June 12, 2013 @04:41PM (#5870585)
Yes, but a literal will still be either an array or an object, so that

  var arr = ['a','b']
will be different from

  var obj = {0:'a',1:'b'}